akhauriyash/Code-Regression huggingface dataset:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll L, N; scanf("%lld%lld", &L, &N);
    vector<ll> X; // 2N + 1 要素, 座標 0 は X[N] にある
    for(int i=0; i<N; i++) {
        ll x; scanf("%lld", &x);
        X.emplace_back(x);
    }
    X.emplace_back(L);
    for(int i=0; i<N; i++) {
        X.emplace_back(X[i] + L);
    }

    ll ans = 0;
    for(int k=0; k<2; k++) {
        int M = X.size();
        // 前半: S[1..N], 後半: S[N+1..2N]
        vector<ll> S(M+1);
        for(int i=0; i+1<M; i++) S[i+1] = S[i] + (X[i+1] - X[i]);
        for(auto e : S) cerr << e << " ";
        cerr << endl;

        ll sum = S[N];
        for(int i=0; i<N; i++) {
            chmax(ans, sum);
            int l = i - i / 2, r = N + i/2 + 1;
            sum -= S[i+1] - S[l];
            sum += S[r] - S[i+1];
        }

        reverse(X.begin(), X.end());
        for(auto &e : X) e *= -1;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;

  cin >> N;
  int tmp = N;

  int W[N];
  int sum1 = 0;

  for (int k = 1; k <= N; k++) {
    cin >> W[k];
    sum1 += W[k];
  }

  sum1 -= W[tmp];
  int sum2 = W[tmp];
  int ans = abs(sum1 - sum2);

  for (int k = (tmp-1); k > 1; k--) {
    sum1 -= W[k];
    sum2 += W[k];
    int diff = abs(sum1 - sum2);
    if (diff < ans) { ans = diff; }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
int main() {
    int n;
    cin >> n;
    Int remain = 0, ans = 0;
    rep(i, n) {
        Int a;
        cin >> a;
        if(remain==1 && a>0){
            ans++;
            a--;
        }
        auto d = a / 2;
        ans += d;
        remain = a - 2 * d;
    }
    PUTS(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  int c[M];
  int Ans[M][N+1];
  for(int i=0;i<M;++i){
    cin >> c[i];
  }
  sort(c,c+M);
  for(int i=0;i<M;++i){
    Ans[i][0]=0;
  }
  for(int i=0;i<=N;++i){
    Ans[0][i]=i;
  }
  for(int m=1;m<M;++m){
    for(int n=1;n<=N;++n){
      Ans[m][n]=Ans[m-1][n];
      if(n>=c[m])Ans[m][n]=min(Ans[m][n], min( Ans[m-1][n-c[m]]+1, Ans[m][n-c[m]]+1) ); 
    }
  }
  cout << Ans[M-1][N] << endl;
}

Measured memory_bytes: 5080
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e15;

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

    ll a[n];
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    ll ans = INF;
    ll snuke = 0;
    rep(i, n-1) {
        snuke += a[i];
        ll araiguma = sum - snuke;
        ll score = abs(snuke - araiguma);
        ans = min(ans, score);
    }

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

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

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

using namespace std;

int n,m;
int pc[1000][1310];

int main(void){
	while(cin >> n >> m){
		if(n==0&&m==0) break;
		rep(i,1000)rep(j,1310) pc[i][j]=0;

		int r; cin >> r;
		rep(i,r){
			int t,a,b,s;
			cin >> t >> a >> b >> s;
			if(s==1)
				pc[a-1][t]+=b;
			else
				pc[a-1][t]-=b;
		}
		rep(i,n)rep(j,1300) pc[i][j+1]+=pc[i][j];
		int q; cin >> q;
		rep(loop,q){
			int ts,te,tm;
			cin >> ts >> te >> tm;
			int ans=0;
			for(int t=ts;t<te;++t){
				bool check=false;
				rep(i,n) if(pc[i][t]==tm) check=true;
				if(check) ans++;
			}
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 6276
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int[] cost = new int[N];
		int[][] A = new int[N][M];
		
		for(int i = 0; i < N; i++) {
			cost[i] = sc.nextInt();
			for(int j = 0; j < M; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		
		int min = Integer.MAX_VALUE;
		
		for (int i=0; i<(Math.pow(2, N)); i++) {
			int[] study = new int[M];
			Arrays.fill(study, X);
			
			int sum = 0;
			
			String s = "-";
			for (int j=0; j<N; j++) {
				if ((1&i>>j) == 1) {
					sum += cost[j];
					for(int k = 0; k < M; k++) {
						study[k] -= A[j][k];
					}
				}
				boolean flag = true;
				for(int k = 0; k < M; k++) {
					if(study[k]>0)flag = false;
				}
				if(flag)min = Math.min(min, sum);
			}
		}
		
		System.out.println((min != Integer.MAX_VALUE)?min:-1);
		sc.close();
	}
}

Measured memory_bytes: 37796
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    ll x; cin>>x;
    ll y=x/100;
    if(105*y>=x) cout<<1<<endl;
    else if(x>=2000) cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
/* ex5_3
   moka223711 */

#include <stdio.h>
#define ROW 101 // マス目の行の上限
#define COL 101 // マス目の列の上限

int main(void){
    // br = black_row, bc = black_column
    // 黒が少なくとも1マス含まれている行,列を記録する 0で初期化
    int row, col, i, j, br[ROW]={0}, bc[COL]={0};
    // マス目の配色を受け取る2次元配列
    char sq[ROW][COL];
    scanf("%d %d", &row, &col);
	
    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
            // マス目の配色を受け取り、黒が1マスでも含まれている行と列はbr[i], bc[j]を1に変える
            scanf(" %c", &sq[i][j]);
            if(sq[i][j]=='#'){
                br[i] = 1;
                bc[j] = 1;
            }
        }
    }
    for(i = 0; i < row; i++){
        // 上から1行ずつ出力していく
        // 黒が少なくとも1マス含まれる行のみ実行
        if(br[i] == 1){
            for(j = 0; j < col; j++){
                // 黒が少なくとも1マス含まれる列のみ実行
                if(bc[j] == 1){
                    // マス目を出力
                    printf("%c", sq[i][j]);
                }
            }
            // 改行を出力
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
Scanf.scanf "%d" (fun n ->
    let module S = Set.Make (struct type t = int * int let compare = compare end) in
    let a = Array.init (n * 3) (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let karr = Array.make (3 * n) 0 in

    let rec init i sum set lim =
        if i = lim then sum, set else
            init (i + 1) (sum + a.(i)) (S.add (a.(i), i) set) lim
    in
    let sum, set = init 0 0 S.empty n in
    let rec loop k sum set =
        if k <= 2 * n then (
            karr.(k) <- sum;
            let set = S.add (a.(k), k) set in
            let sum = sum + a.(k) in
            let (mk, _) as mi = S.min_elt set in
            loop (k + 1) (sum - mk) (S.remove mi set)
        )
    in
    loop n sum set;

    let sum, set = init (2 * n) 0 S.empty (3 * n) in

    let rec loop k sum set =
        if k >= n then (
            karr.(k) <- karr.(k) - sum;
            let k = k - 1 in
            let set = S.add (a.(k), k) set in
            let sum = sum + a.(k) in
            let (mk, _) as mx = S.max_elt set in
            loop k (sum - mk) (S.remove mx set)
        )
    in
    loop (2 * n) sum set;

    let rec loop i acc =
        if i > 2 * n then acc else
            loop (i + 1) (max acc karr.(i))
    in
    loop n min_int |> Printf.printf "%d\n"
)

Measured memory_bytes: 27948
#include<iostream>

using namespace std;

int main(){
    int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1}; 
    int x, y;
    cin >> x >> y;
    cout << (a[x] == a[y] ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;
const double EPS=1E-9;
bool gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j];
  
  for(int i=0;i<n;i++)B[i][n]=b[i];
  
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++)if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;
    swap(B[i],B[pivot]);
    for(int j=0;j<n;j++)
      if(i!=j&&B[j][i])
	for(int k=i;k<=n;k++)B[j][k]=(B[j][k]+B[i][k])%2;
  }
  for(int i=0;i<n;i++)if(B[i][i]==0&&B[i][n]==1) return 0;
  return 1;
}

int h,w,d,mp[25][25];

int main(){
  while(1){
    cin>>w>>h>>d;
    if(!w&&!h&&!d)break;
    mat A(h*w,vec(h*w));
    vec B(h*w);
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin>>mp[i][j];
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	int idx=w*i+j;
	B[idx] = mp[i][j];
	for(int y=0;y<h;y++)
	  for(int x=0;x<w;x++){
	    int t = abs(i-y)+abs(j-x);
	    if(t==d||t==0)A[idx][w*y+x]=1;				
	  }
      }
    cout<<gauss_jordan(A,B)<<endl;
  }
  return 0;
}

Measured memory_bytes: 5948
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[]str = Console.ReadLine().Split();
		int K = int.Parse(str[0]);
		int N = int.Parse(str[1]);
		int[]A = new int[N];
		long sum = K;
		long a1 = 0;
		string[]str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str2[i]);
		}
		a1 = K-Math.Abs(A[0]-A[N-1]);
		for(var i=1;i<N;i++){
			a1 = Math.Max(a1,Math.Abs(A[i]-A[i-1]));
		}
		long ans = sum-a1;
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 31836
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	public K()
	{
		WriteLine(S());
	}
	long S()
	{
		var N = int.Parse(ReadLine());
		var A = ReadLine().Split().Select(int.Parse).ToArray();
		var d = new Dictionary<int, int>();
		foreach (var a in A) if (!d.ContainsKey(-a)) d[-a] = 1; else d[-a]++;
		var e = new SortedDictionary<int, int>();
		foreach (var x in d) if (x.Value >= 4) e[x.Key] = 2; else if (x.Value >= 2) e[x.Key] = 1;
		if (e.Count == 0) return 0;
		var m = e.Keys.First();
		if (e.Count == 1 && e[m] < 2) return 0;
		if (e[m] >= 2) return (long)m * m;
		e.Remove(m);
		return (long)m * e.Keys.First();
	}
}

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

int main() {
  int H1, M1, H2, M2, K, ans;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  ans = (H2-H1)*60+(M2-M1)-K;
  if(ans<0) ans=24*60+ans;
  cout << ans << endl;
}

Measured memory_bytes: 3616
n = int(input())
# = map(int, input().split())
a = list(map(int, input().split()))
# = [int(input()) for _ in range()]
cnt1 = 0
cnt2 = 0
for i in range(n):
    if a[i] % 2 == 0:
        cnt1 += 1
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            cnt2 += 1
print("APPROVED" if cnt1 == cnt2 else "DENIED")


Measured memory_bytes: 2940
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int x,y,a,r,g,b,c,tyu,tei,la,lb;
    cin>>x>>a>>b;
    (x-a<0)?(la=a-x):(la=x-a);
    (x-b<0)?(lb=b-x):(lb=x-b);
    if(la<lb){
        cout<<"A"<<endl;
    }
    else{
        cout<<"B"<<endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    int a,b;
    char s[10],t[10],u[10];
    scanf("%s",s);
    scanf("%s",t);
    scanf("%d%d",&a,&b);
    scanf("%s",u);   
   if(strcmp(s,u)==0) a--;
   if(strcmp(t,u)==0) b--;
   printf("%d %d",a,b);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int n, k; cin >> n >> k;
	if (k == 1)cout << 0 << endl;
	else cout << n - k << endl;
}

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

int main(){
    string s;
    string t;
    cin >> s >> t;
    for(int i = 0; i < s.size();i++){
        if(s[i] != t[i]){
            cout << "No" << endl;
            break;
        }else if(i == s.size()-1){
            if(t.size() == s.size() + 1){
                cout << "Yes" <<endl;
            }else{
                cout << "No" <<endl;
            }
        }
    }
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n ; i++)

int main(){
    int N, K;
    cin >> N >> K;
    int initNum = 1;
    rep(i, N){
        if(initNum < K){
            initNum *= 2;
        }else{
            initNum += K;
        }
    }

    cout << initNum << endl;
}

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

using namespace std;

using ll = long long;

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

    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << " ";
    if (a + b <= n) cout << "0\n";
    else if (n == min(a, b)) cout << n << endl;
    else cout << (a + b) - n << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    string a, b;
    for (int i = 0; i < m; i++)
        a += char(n + 48);
    for (int j = 0; j < n; j++)
        b += char(m + 48);
    cout << min (a, b) << endl;

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int SIZE = 100010;
long long A[SIZE];
int pos[SIZE];
int main() {
    long long N;
    int x,M;
    cin>>N>>x>>M;
    for(int i=0;i<M;i++)pos[i]=-1;
    A[0]=x;
    pos[x]=0;
    int cycle_len=-1;
    for(int i=1;;i++){
        A[i]=(A[i-1]*A[i-1])%M;
        if(pos[A[i]]!=-1){
            cycle_len=i;
            break;
        }
        pos[A[i]]=i;
    }
    int st=pos[A[cycle_len]];
    long long answer=0;
    for(int i=0;i<cycle_len;i++){
        if(i>=N)break;
        if(i<st)answer+=A[i];
        else{
            long long cnt=(N-st)/(cycle_len-st)+(((N-st)%(cycle_len-st))>(i-st));
            answer+=cnt*A[i];
        }
    }
    cout<<answer<<endl;
    return 0;
}


Measured memory_bytes: 4360
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        d: i64,
        x_y: [(i64, i64); n],
    };
    let d2 = d.pow(2);
    let mut ans = 0;
    for (x, y) in x_y.iter() {
        if x.pow(2) + y.pow(2) - d2 <= 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 7844
n = int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

yakusu = make_divisors(n)
l_yakusu = len(yakusu)
idx = 0

mx = 10

for a in range(1,10**5+1):
    if a>n:
        break
    if idx<l_yakusu and a==yakusu[idx]:
        idx += 1
        keta_a = len(str(a))
        keta_b = len(str(n//a))
        f = max(keta_a, keta_b)
        mx = min(mx, f)

print(mx)

Measured memory_bytes: 9236
#include<bits/stdc++.h>
#define F(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RF(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
/*----------------------------------------------------------------------*/

const int N = 3005;
int dp[N][N],par[N][N]; // 0 - i-1,j. 1 - i,j-1 and 2 - i-1,j-1.
string s,t;

void solve(int sx, int tx, string &ans) {
	if(sx<=0 || tx<=0) return;
	switch(par[sx][tx]) {
		case 0:
			solve(sx-1, tx, ans);
			break;
		case 1:
			solve(sx, tx-1, ans);
			break;
		case 2:
			solve(sx-1, tx-1, ans);
			ans.push_back(s[sx-1]);
			break;
	}
}

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    cin>>s>>t;

    int sz[2];
    sz[0]=s.size(); sz[1]=t.size();
    memset(dp, -1, sizeof(dp)); memset(par, -1, sizeof(par));
    dp[0][0]=0;
    F(i, 1, sz[0]+1) {
    	dp[i][0]=0;
    }

    F(i, 1, sz[1]+1) {
    	dp[0][i]=0;
    }

    F(i, 1, sz[0]+1) {
    	F(j, 1, sz[1]+1) {
    		par[i][j]=0;
    		if(dp[i][j-1]>dp[i-1][j]) par[i][j]=1;
    		dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
    		if(s[i-1] == t[j-1]) {
    			if(1+dp[i-1][j-1]>dp[i][j]) par[i][j]=2;
    			dp[i][j]=max(dp[i][j], 1+dp[i-1][j-1]);
    		}
    	}
    }
    string ans="";
    solve(sz[0], sz[1], ans);
    cout<<ans;

    return 0;
}/*

*/


Measured memory_bytes: 70912
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]

inf=3000

def mp(g,a,b,c):
    if g==N:
        return abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c)>0 else inf

    l0=mp(g+1,a+l[g],b,c)+10
    l1=mp(g+1,a,b+l[g],c)+10
    l2=mp(g+1,a,b,c+l[g])+10
    l3=mp(g+1,a,b,c)
    
    return min(l0,l1,l2,l3)

print(mp(0,0,0,0))

Measured memory_bytes: 3064
import math
d=input().split()
N,K=int(d[0]),int(d[1])
a=math.factorial(K-1)
b=math.factorial(N-K+1)
if N-K+2<=K:
  for i in range(1,N-K+2):
    t=b//(math.factorial(i)*math.factorial(N-K-i+1))
    s=(a//(math.factorial(i-1)*math.factorial(K-i)))*t%(10**9+7)
    print(s)
  for i in range(N-K+2,K+1):
    print(0)
else:
    for i in range(1,K+1):
       t=b//(math.factorial(i)*math.factorial(N-K-i+1))
       s=(a//(math.factorial(i-1)*math.factorial(K-i)))*t%(10**9+7)
       print(s)
  

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


struct UnionFindTree {
  std::vector<int> data;

  UnionFindTree(int size) : data(size, -1) { }
  bool Unite(int x, int y) {
    x = Root(x); y = Root(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool IsSameRoot(int x, int y) {
    return Root(x) == Root(y);
  }
  int Root(int x) {
    return data[x] < 0 ? x : data[x] = Root(data[x]);
  }
  int Size(int x) { return -data[Root(x)]; }
};

int main() {
  int N, K, L; cin >> N >> K >> L;
  UnionFindTree road(N + 1), railroad(N + 1);

  for (int i = 0; i < K; ++i) {
    int p, q; cin >> p >> q;
    road.Unite(p, q);
  }

  for (int i = 0; i < L; ++i) {
    int r, s; cin >> r >> s;
    railroad.Unite(r, s);
  }

  map<int, pair<int, int>> m;
  map<pair<int, int>, int> sizes;
  for (int n = 1; n <= N; ++n) {
    pair<int, int> p = {road.Root(n), railroad.Root(n)};
    m[n] = p;
    sizes[p]++;
  }

  for (int n = 1; n <= N; ++n) {
    cout << sizes[m[n]] << endl;
  }
}


Measured memory_bytes: 25600
import java.util.*;

public class Main{

    void solve(){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int x = scan.nextInt();
        int out = 0;
        for(int i = 0; i <= a; i++){
            for(int j = 0; j <= b; j++){
                int k = (x - i * 500 - j * 100) / 50;
                if(0 <= k && k <= c) out++;
            }
        }
        System.out.println(out);
    }


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


Measured memory_bytes: 35748
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

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

int main(){
    int N, X; cin >> N >> X;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    
    int ans = abs(X - v[0]);
    rep(i, N){
        ans = gcd(abs(X - v[i]), ans);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX  1e18
#define ss 1e15
#define pb push_back

int main() {
    string s;
    cin>>s;
    int n = s.length();
    int count = 0;
    for(int i=0;i<n;i++){
        if(s[i] == 'o')count++;
    }
    int left = 15 - n;
    if(count + left >= 8){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
    return 0;
}


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

int d[4] = {0, 1, 0, -1};
long long n;
vector<long long> perm;
vector<vector<long long>> cost;
vector<vector<bool>> ch;

bool isvalid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < n; }
long long solve();

int main() {
  cin >> n;
  perm.resize(n * n);
  for (auto &x : perm) {
    cin >> x;
    --x;
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  cost.resize(n, vector<long long>(n, 0));
  ch.assign(n, vector<bool>(n, 0));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      cost[i][j] = min({(long long)i, n - 1 - i, (long long)j, n - 1 - j});
  long long res = 0;
  for (auto p : perm) {
    int x = p / n, y = p % n;
    res += cost[x][y];
    ch[x][y] = 1;
    queue<int> qu;
    qu.push(p);
    while (qu.size()) {
      int now = qu.front();
      qu.pop();
      x = now / n, y = now % n;
      for (int i = 0; i < 4; ++i) {
        int tx = x + d[i], ty = y + d[1 ^ i], c = cost[x][y];
        if (!isvalid(tx, ty)) continue;
        c += 1 - ch[x][y];
        if (c < cost[tx][ty]) {
          cost[tx][ty] = c;
          qu.push(tx * n + ty);
        }
      }
    }
  }
  return res;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s;
    cin >> s;

    int64_t m = s.size();

    vector a(1, 0L);
    int64_t t = 0;
    for (auto c : s) {
        if (c == '0') {
            a.push_back(t);
        } else {
            ++t;
        }
    }
    a.push_back(t);

    int64_t k;
    cin >> k;
    k = min(k, a.back());

    int64_t n = a.size();

    constexpr auto M = 998244353L;

    vector dp(vector(k + 1, vector(a.back() + 1, 0L)));
    int64_t mk = 0;
    dp[0][0] = 1;
    for (auto i : irange(0L, n - 1)) {
        for (auto j : irange(mk, -1L, -1L)) {
            auto r = min(k - j, a[i + 1] - a[i]);
            for (auto d : irange(1L, r + 1L)) {
                auto w = j + d;
                for (auto c : irange(0L, a.back() - a[i + 1] + 1)) {
                    auto b = c + d;
                    dp[w][c] += dp[j][b];
                    if (dp[w][c] >= M) {
                        dp[w][c] -= M;
                    }
                }
            }

            for (auto c : irange(1L, a.back() - a[i + 1] + 1)) {
                dp[j][c] += dp[j][c - 1];
                if (dp[j][c] >= M) {
                    dp[j][c] -= M;
                }
            }
        }
        mk = min(k, mk + a[i + 1] - a[i]);
    }

    int64_t ans = 0;
    for (auto i : irange(0L, mk + 1)) {
        ans += dp[i][0];
    }

    cout << ans % M << "\n";
}


Measured memory_bytes: 3944
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define _D(p) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p)<<std::endl;
#define _D2(p,q) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p) << ", " #q " = "<<(q)<<std::endl;
#define _DN(v) std::cout<<"L"<<__LINE__<<" : " #v " = ["; rep(i,(v).size()) {std::cout<<v[i]<<(i==v.size()-1?"":", ");}std::cout<<"]"<<std::endl;
#define _DNN(v) std::cout<<"L"<<__LINE__<<" : " #v " = [" << std::endl; rep(i,(v).size()) {std::cout<<"    [";rep(j,(v)[0].size()){std::cout<<v[i][j]<<(j==v[0].size()-1?"":", ");}std::cout<<"],"<<std::endl;}std::cout<<"]"<<std::endl;
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int main(int argc, char const *argv[]) {
    string s;
    cin >> s;
    int l = -1, r = -1;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A') {l = i; break;}
    }
    for (int i = s.size() - 1; i >= 0; --i) {
        if (s[i] == 'Z') {r = i; break;}
    }
    cout << r - l + 1 << endl;
    return 0;
}

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

static const int INF = 1145141919;

int main()
{
	int n;
	cin >> n;
	int h[100002];
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	int dp[100002] = {};
	dp[100000] = dp[100001] = INF;
	for (int i = 0; i < 100002; ++i)
	{
		dp[i] = INF;
	}
	dp[0] = 0;
	for (int i = 0; i < n; ++i)
	{
		dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i + 1]));
		dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i + 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>  
#include <algorithm>
using namespace std;  
int main() { 	
	int a,b,c;
	int d, e, f;
	scanf("%d %d", &a, &b);
	if(a==b || abs(a-b)==1){
		printf("%d", a+b);
	}
	else if(abs(a-b)!=1){
		if(a>b){
			printf("%d", a+a-1);
		}
		if(b>a){
			printf("%d",b+b-1);
		}
	}
	
	
}






Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int M[100][100];
  int j,i,n,u,k,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j)printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2108
#include <stdio.h>
#define LEN 4

int isBad(int s);

int main(void) {

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

    if ( isBad(s) ) {
        puts("Bad");
    } else {
        puts("Good");
    }

    return 0;
}

int isBad(int s) {

    int i;
    int p, n;

    p = s % 10;
    s /= 10;

    for ( i = 1; i < LEN; i++ ) {
        n = s%10;
        s /= 10;
        if ( n == p ) { return 1; }
        p = n;
    }

    return 0;
}

Measured memory_bytes: 128
import re
compiled = re.compile(r"(R*)(RL)(L*)")
s=input()
ans = [0 for i in range(len(s))]
matched=list(compiled.findall(s))
pos=0

for i in range(len(matched)):
    m=matched[i]
    pos+=len(m[0])
    ans[pos]+=1
    ans[pos+1]+=1
    if(len(m[0])%2):
        ans[pos]+=+len(m[0])//2
        ans[pos+1]+=1+len(m[0])//2
    else:
        ans[pos]+=len(m[0])//2
        ans[pos+1]+=len(m[0])//2
    if(len(m[2])%2):
        ans[pos]+=1+len(m[2])//2
        ans[pos+1]+=+len(m[2])//2
    else:
        ans[pos]+=len(m[2])//2
        ans[pos+1]+=len(m[2])//2
    pos+=2+len(m[2])

print(" ".join(map(str,ans)))


Measured memory_bytes: 64924
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

vector<vector<long long> > mul(vector<vector<long long> > v1, vector<vector<long long> > v2){
    vector<vector<long long> > ret(v1.size(),vector<long long>(v2[0].size(),0));
    for(int i=0;i<v1.size();i++) {
        for(int j=0;j<v2[0].size();j++) {
            for(int k=0;k<v1.size();k++) {
                ret[i][j]+=v1[i][k]*v2[k][j];
            }
        }
    }
    return ret;
}

vector<vector<long long> > powmatrix(vector<vector<long long> > vv, vector<vector<long long> > v, long long n){
    vector<vector<vector<long long> > > vvv;
    vvv.push_back(vv);
    for(long long i = 0; i < 64; i++){
        vvv.push_back(mul(vvv[i],vvv[i]));
    }
    vector<vector<long long> > v1(vv.size(), vector<long long>(vv.size(), 0));
    for(int i = 0; i < vv.size(); i++)v1[i][i] = 1;
    for(int i = 0; i < 64; i++){
        if((n>>i)&1){
            v1 = mul(v1,vvv[i]);
        }
    }
    v = mul(v1,v);
    return v;
}

int main() {
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  vector<vector<long long> > v(3, vector<long long>(1, 0));
  v[0][0] = a;
  v[1][0] = b;
  v[2][0] = c;
  vector<vector<long long> > vv(3, vector<long long>(3, 0));
  vv[0][0] = 0; vv[0][1] = 1; vv[0][2] = 1;
  vv[1][0] = 1; vv[1][1] = 0; vv[1][2] = 1;
  vv[2][0] = 1; vv[2][1] = 1; vv[2][2] = 0;

  vector<vector<long long> > va = powmatrix(vv,v,k);
    ll a1 = va[0][0];
    ll b1 = va[1][0];
    ll c1 = va[2][0];
    cout << a1 - b1 << endl;
  return 0;
}

Measured memory_bytes: 256
// abc165_d
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int floor(ll x, ll y) {
  int ans = x/y;
  return ans;
}

int main()
{
  ll a,b,n,ans;
  cin>>a>>b>>n;
  if (n>=b) {

    ans=(floor(a*(b-1), b)-a*floor(b-1,b));
  } else {
    ans=(floor(a*n,b)-a*floor(n,b));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		ArrayList<String> list = new ArrayList<>();
		int n = scan.nextInt();
		int l = scan.nextInt();
		for (int i = 0; i < n; i++) {
			list.add(scan.next());
		}
		Collections.sort(list);
		for(int i = 0; i < n;i++){
			System.out.print(list.get(i));
		}
		System.out.println();

	}
}

Measured memory_bytes: 22100
S=str(input())
cnt=0
num=0
for i in range(len(S)):
    if S[i]=="1":
        cnt+=1
    else:
        num=S[i]
        break
#print(num)
K=int(input())
if K<=cnt:
    print("1")
elif K>cnt:
    print(num)


Measured memory_bytes: 2940
#include<stdio.h>

int main(void)
{
	int x, y;
	while (1){
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0){
			break;
		}
		else if (x < y){
			printf("%d %d\n", x, y);
		}
		else{
			printf("%d %d\n", y, x);
		}
	}

	return 0;
	
}

Measured memory_bytes: 600
#include<stdio.h>

int Abs(int x, int y) {
  return x-y >= 0 ? x-y:y-x;
}


int main() {
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  int f = 0;
  if (Abs(a, c) <= d) f = 1;
  if (Abs(a, b) <= d && Abs(b, c) <= d) f = 1;
  if (f == 1) printf("Yes\n");
  else printf("No\n");
  return 0;
}



Measured memory_bytes: 128
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n;
	int min_so_far = INF;	
	int ct =0;
	cin >> n;
	for(int i =0; i < n; ++i)
	{
		int x;
		cin >> x;
		if(x < min_so_far)
		{
			ct++;
			min_so_far = x;
		}
		
	}


	cout << ct;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define trav(x, c) for(auto &x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))

#define dbg(x) cerr << #x << " = " << x << endl;
#define dbgall(x) cerr << #x << " = "; for(auto i_ : x) cerr << i_ << " "; cerr << endl;
#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

//=========================

void run_test() {
	int n; cin >> n;
	cout << fixed << setprecision(6) << (double) (n - n / 2) / n << endl;
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


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

int main() {
    vector<char> number(3);
    for(int i = 0; i < 3; i++){
        cin >> number.at(i);
    }
    bool seven = false;
    if(number.at(0) == '7'){
        seven = true;
    }
    if(number.at(1) == '7'){
        seven = true;
    }
    if(number.at(2) == '7'){
        seven = true;
    }
    if(seven){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3620
import java.util.Scanner;

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

        StringBuilder str = new StringBuilder(scan.next());	//文字列入力
        int count = scan.nextInt();	//命令回数入力

        for(int i=0; i<count; i++) {

        	String com = scan.next();

    		int a = scan.nextInt();	//入力
    		int b = scan.nextInt() + 1;	//入力

        	switch(com) {

        	case "print":

        		System.out.println(str.substring(a, b));
        		break;

        	case "replace":

        		String p = scan.next();
        		str.replace(a,b, p);
        		break;

        	case "reverse":

        		String c = str.substring(a, b);
        		StringBuilder str2 = new StringBuilder(c);
        		str2.reverse();
        		str.replace(a,b,str2.toString());
        		break;

        	}

        }
    }
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  ll n, ans; 
  cin >> n;
  if(n%2LL==0) ans = n;
  else ans = 2LL * n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
ans = [0] * (N+1)
for i in range(M):
    f, t = map(int, input().split())
    graph[f].append(t)
    graph[t].append(f)

D = deque([1])
checked = [0] * (N+1)
checked[0] = 1
checked[1] = 1
while D:
    n = D.popleft()
    for i in graph[n]:
        if checked[i] == 1:
            continue
        checked[i] = 1
        ans[i] = n
        D.append(i)

if 0 in checked:
    print("No")
else:
    print("Yes")
    for i in range(2,N+1):
        print(ans[i])

Measured memory_bytes: 34876
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int a, b, c;
	cin >>a >> b >> c;
	int ans = a + b + c;
	if (a >= b && a >= c) {
		ans -= a;
	}
	else if (b >= a && b >= c) {
		ans -= b;
	}
	else if (c >= b && c >= a) {
		ans -= c;
	}
	cout << ans << endl;
	return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        char temp;
        stack<int> as, bs, cs;
        string a, b;
        cin >> a >> b;
        rep(j, a.length()) as.push(a[j] - '0');
        rep(j, b.length()) bs.push(b[j] - '0');
        int keta = max(as.size(), bs.size());
        int aa, bb, cc = 0;
        rep(j, keta)
        {
            if (as.size() != 0)
            {
                aa = as.top();
                as.pop();
            }
            else
            {
                aa = 0;
            }

            if (bs.size() != 0)
            {
                bb = bs.top();
                bs.pop();
            }
            else
            {
                bb = 0;
            }
            int hoge = aa + bb + cc;
            cc = hoge / 10;
            cs.push(hoge - 10 * cc);
        }
        if (cc != 0)
        {
            cs.push(cc);
        }
        if (cs.size() > 80)
        {
            cout << "overflow";
            if(DEBUG) cout<<cs.size();
        }
        else
        {
            while (cs.size() != 0)
            {
                cout << cs.top();
                cs.pop();
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#ifdef TOPOLOGY
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;
	
int main() {
	int a, b;
	char s[22];
	cin >> a >> b >> s;
	int n = (int)strlen(s);
	if (n != a + b + 1) return !printf("No\n");
	for (int i = 0; i < a; i++) {
		if (s[i] < '0' || s[i] > '9') return !printf("No\n");
	}
	if (s[a] != '-') return !printf("No\n");
	for (int i = a + 1; i < a + b + 1; i++) {
		if (s[i] < '0' || s[i] > '9') return !printf("No\n");
	}
	cout << "Yes" << endl;
	return 0;
}


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

bool subsort(pair<pair<string,int>,int> lhs, pair<pair<string,int>,int> rhs){
    if(lhs.first.first == rhs.first.first){
        return lhs.first.second > rhs.first.second;
    }
    else{
        return lhs < rhs;
    }
}
 
int main() {
    int N;
    cin >>N;
    
    vector< pair<pair<string,int>,int >> pairvec(N);
    for(int i=0; i<N; i++){
        cin >> pairvec.at(i).first.first;
        cin >> pairvec.at(i).first.second;
        pairvec.at(i).second = i+1;
    }

    sort(pairvec.begin(), pairvec.end(), subsort);
    for(int i=0; i<N; i++){
        cout << pairvec.at(i).second << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
using namespace std;

typedef long long ll;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

typedef long long ll;
ll M = 1e9 + 7;
ll n, m, s, a[2005];
ll f(ll p) {
	return (p * (p - 1)) / 2;
}
int main()
{
	ll i, j;
//	freopen ("input.txt", "r", stdin);
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		scanf ("%lld", &a[i]);
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (a[i] > a[j]) {
				s = (s + f(m)) % M;
				if (i < j) s = (s + m) % M;
			}
		}
	}
	cout << s;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	ll sum = 0;
	vector<ll>a(n);
	vector<int>b(m);
	vector<ll>c(m);
	vector<pair<ll,int>>p(m);
	repp(i, 0, n)cin >> a[i];
	sort(a.begin(), a.end());
	repp(i, 0, m) {
		cin >> b[i] >> c[i];
		p[i] = make_pair(c[i], b[i]);
	}sort(p.begin(), p.end());
	reverse(p.begin(), p.end());
	int k = 0;
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < p[i].second; ++j) {
			if (p[i].first >= a[k])a[k] =p[i].first;
			else {
				for (int h = 0; h < a.size(); ++h) {
					sum += a[h];
				}
				cout << sum << endl;
				return 0;
			}
			++k;
		}
	}
	for (int h = 0; h < a.size(); ++h) {
		sum += a[h];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = 2000000000;

int main() {
  int n,m,h[110000],ma[110000];
  cin >> n >> m;
  for(int i = 1; i <= n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for(int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  
  int cnt = 0;
  for(int i = 1; i <= n; i++)
    if(h[i] > ma[i]) cnt++;
  
  cout << cnt << endl;
}

Measured memory_bytes: 4388