akhauriyash/Code-Regression huggingface dataset:
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
void fo (){fflush(stdout);}
using namespace std;
ll fact (int x ){return (x <= 1 ? 1 : 1LL * x * fact (x-1));}
int n , m , ans ;
string x[2000];
vector <int> row[2000],col[2000];
int lessme (int v,vector <int> vec[], int id)
{
  int l = 0 , r = SZ(vec[id])-1 , m , j = -1 ;
  while (l <= r )
  {
    m = (l+r)>>1;
    if (vec[id][m] < v )
    {
      j = vec[id][m] ;
      l = m + 1 ;
    }else
    r = m-1;
  }
  return j ;
}
int moreme (int v,vector <int> vec[] , int id )
{
  int l = 0 , r = SZ(vec[id])-1 , m , j = -1 ;
  while (l <= r )
  {
    m = (l+r)>>1;
    if (vec[id][m] > v )
    {
      j = vec[id][m] ;
      r = m - 1 ;
    }else
    l = m+1;
  }
  return j ;
}
int main ()
{

scanf ("%d%d" , &n ,&m);
for (int i =0 ; i < n ;i++)cin >> x[i];
for (int i =0 ; i < n ;i++)
{
  for (int j =0 ; j < m ;j++)
  {
    if (x[i][j] == '.' && SZ(row[i]) == 0 )row[i].pb(j);
    if (x[i][j] == '.' && (j+1 == m ||(j+1 < m && x[i][j+1] =='#') || (j - 1 >=0 && x[i][j-1] == '#')) )
    row[i].pb(j);
  }
}
for (int i = 0 ; i < m ;i++)
{
  for (int j= 0; j < n ;j++)
  {
    if (x[j][i] == '.' && SZ(col[i]) == 0 )col[i].pb(j);
    if (x[j][i] == '.' && (j+1 == n ||(j+1 < n && x[j+1][i] =='#') || (j - 1 >=0 && x[j-1][i] == '#')) )
    col[i].pb(j);
  }
}
for (int i =0 ; i < n ;i++)
{
  for (int j =0 ; j < m ;j++)
  {
    if (x[i][j] != '.')continue ;
    int cur =0 ;
    int l = lessme(j , row , i );
    int r = moreme(j , row , i );
    if (l == -1 || (j - 1 >= 0 && x[i][j-1] == '#'))l = j ;
    if (r == -1 || (j + 1 < m && x[i][j+1] == '#') )r = j ;

    cur += r - l + 1 ;
    l = lessme(i , col , j );
    r = moreme(i , col , j );
    if (l == -1 || (i - 1 >= 0 && x[i-1][j] == '#'))l = i ;
    if (r == -1 || (i+1 < n && x[i+1][j] =='#'))r = i ;
    cur += r - l + 1 ;
    cur--;
    ans = max (ans , cur );
  }
}
printf ("%d\n" ,ans );
cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 20608
n = list(input())
if n[len(n)-1] == '2' or n[len(n)-1] == '4' or n[len(n)-1] == '5' or n[len(n)-1] == '7' or n[len(n)-1] == '9':
    print('hon')
elif n[len(n)-1] == '3':
    print('bon')
else:
    print('pon')

Measured memory_bytes: 9056
n=int(input())
A=list(map(int,input().split()))
A=list(map(lambda x:x//400 if x<3200 else 8,A))
n_red=A.count(8)
n_min=len(set(A))
n_8=1 if n_red else 0
print(1 if n_min==1 and list(set(A))[0]==8 else n_min-n_8,n_min+n_red-n_8)


Measured memory_bytes: 3060
#include <functional>
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <tuple>
#include <assert.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define TR(i,x) for(__typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define CLEAR(x) memset(x,0,sizeof(x))
#define FILL(x,c) memset(x,c,sizeof(x))

using namespace std;

#define PB push_back
#define MP make_pair

typedef map<int,int> MII;
typedef map<string,int> MSI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long double> VD;
typedef pair<int,int> PII;
typedef long long int64;
typedef long long LL;
typedef unsigned int UI;
typedef long double LD;
typedef unsigned long long ULL;

const int MOD = 1000000007;

const int N = 200007;

LL frac[N];

int a[N];

int main() {
    frac[0] = 1;
    for (int i = 1; i < N; ++i) {
        frac[i] = frac[i - 1] * i % MOD;
    }
    int n;
    cin >> n;
    REP(i, n) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n);

    LL answer = 1;
    int current = 0;
    for (int i = 0; i < n; ++i) {
        if (current == 0) {
            current = 1;
            continue;
        }
        assert (a[i] > 2 * current - 1);
        if (a[i] >= 2 * current + 1) {
            ++current;
            continue;
        }

        answer *= current + 1;
        answer %= MOD;
    }
    answer *= frac[current];
    answer %= MOD; 
    cout << answer << endl;
    return 0;
}

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


int main(){
    int a,b,c,d,e;
    int k;
    cin >> a >> b >> c >> d >> e >> k;
    /*
    cout << a << endl;
    cout << e << endl;
    cout << k << endl;
    */
    if( e-a <= k ){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;

int rot[24][6] = {
	{0,1,2,3,4,5}, {0,2,4,1,3,5}, {0,4,3,2,1,5}, {0,3,1,4,2,5},
	{1,5,2,3,0,4}, {1,2,0,5,3,4}, {1,0,3,2,5,4}, {1,3,5,0,2,4},
	{2,5,4,1,0,3}, {2,4,0,5,1,3}, {2,0,1,4,5,3}, {2,1,5,0,4,3},
	{3,4,5,0,1,2}, {3,5,1,4,0,2}, {3,1,0,5,4,2}, {3,0,4,1,5,2},
	{4,0,2,3,5,1}, {4,2,5,0,3,1}, {4,5,3,2,0,1}, {4,3,0,5,2,1},
	{5,4,2,3,1,0}, {5,2,1,4,3,0}, {5,1,3,2,4,0}, {5,3,4,1,2,0}
};

vector<vector<int> > cond[8] = {
	{},
	{{3,0,2}},
	{{1,1,4}},
	{{1,0,4},{2,2,3}},
	{{0,3,5}},
	{{0,2,5},{3,4,2}},
	{{0,1,5},{4,5,1}},
	{{0,0,5},{2,6,3},{4,4,1}}
};

struct State { int id, r; };
State pz[8];

string dice[8];
bool used[8];

string solve(int x) {
	if (x == 8) return "YES";
	for (int i=1; i<8; ++i) {
		if (used[i]) continue;
		for (int j=0; j<24; ++j) {
			bool ok = true;
			for (int k=0; k<(int)cond[x].size(); ++k) {
				int face1 = rot[j][cond[x][k][0]];
				int bloc2 = cond[x][k][1];
				int face2 = rot[pz[bloc2].r][cond[x][k][2]];
				if (abs(dice[i][face1] - dice[pz[bloc2].id][face2]) != 32) {
					ok = false; break;
				}
			}
			if (ok) {
				pz[x].id = i; pz[x].r = j;
				used[i] = true;
				if (solve(x+1) == "YES") return "YES";
				used[i] = false;
			}
		}
	}
	return "NO";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	while (cin >> dice[0], dice[0] != "0") {
		for (int i=1; i<8; ++i) cin >> dice[i];
		memset(used, false, sizeof used);
		used[0] = true;
		pz[0].id = 0;
		string res = "NO";
		for (int i=0; i<24; ++i) {
			pz[0].r = i;
			if (solve(1) == "YES") {
				res = "YES"; break;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
import java.util.*;

public class Main {

	final int MAX_N = 100009;
	final int MAX_DEPTH = 20;
	double[][] dp = new double[MAX_N][MAX_DEPTH];
	double[][] prob = new double[MAX_N][MAX_DEPTH];

	void run(){
		Scanner in = new Scanner(System.in);
		init();
		for(;;){
			int n = in.nextInt();
			if(n == 0) return ;
			System.out.printf("%.10f\n", solve(n));
		}
	}

	void init(){
		dp[1][1] = 1.0;
		prob[1][1] = 1.0;
		for(int i=2; i<MAX_N-1; i++){
			for(int j=0; j<MAX_DEPTH; j++){
				if(j==0){
					for(int k=0; k<MAX_DEPTH; k++){
						prob[i][j] += prob[i-1][k] * (1.0 - 1.0/(1<<k));
					}
					for(int k=0; k<MAX_DEPTH; k++){
						dp[i][j] += prob[i-1][k] * (1.0 - 1.0/(1<<k)) * dp[i-1][k] / prob[i][j];
					}
				}
				else{
					prob[i][j] += prob[i-1][j-1] * (1.0/(1<<(j-1)));
					dp[i][j] += (dp[i-1][j-1] + 1.0);
				}
			}
		}
	}

	double solve(int n){
		double ret = 0.0;
		for(int i=0; i<MAX_DEPTH; i++){
			ret += prob[n][i] * dp[n][i];
		}
		return ret;
	}

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

Measured memory_bytes: 48000
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<stack>
#include<cmath>
#define ll long long
using namespace std;
const int N=2e5+5;
const int M=1e8;
const ll Max=1e18+1000;
ll a[N];

int main()
{
	int k;
	string s;
	while(cin>>k>>s)
	{
		int len=s.length();
		if(len<=k)
		cout<<s<<endl;
		else
		{
			for(int i=0;i<k;i++)
			cout<<s[i];
			cout<<"..."<<endl;
		}
	}
	return 0;
}

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

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

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

fn prime_factorization(mut n: usize) -> Vec<(usize, usize)> {
    let mut i = 2;
    let mut ans = vec![];
    while i*i <= n {
        let mut cnt = 0;
        while n%i == 0 {
            n /= i;
            cnt += 1;
        }
        if cnt > 0 {
            ans.push((i, cnt));
        }
        i += 1;
    }
    if n > 1 {
        ans.push((n, 1));
    }
    ans
}

const MOD:usize = 1e9 as usize + 7;

fn main() {
    input!{
      n: usize,
    }
    let mut cnt = vec![0; 1001];

    for v in 2..n+1 {
        let divs = prime_factorization(v);
        for &(v, c) in divs.iter() {
            cnt[v] += c;
        }
    }

    let mut ans = 1;
    for i in 2..n+1 {
        ans *= cnt[i]+1;
        ans %= MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(void) {
  int N, Y;
  cin >> N >> Y;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= (N - i); j++) {
      if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
        cout << i << ' ' << j << ' ' << (N - i - j) << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, M;
    cin >> N >> M;
    peri(i, M / N) {
        if(M % i == 0) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


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

int main(){
   std::string S;
   std::cin >> S; 
   int n = S.size();
   int min = 1000;
   for(int i=0; i<n-2; ++i){
      int X = (S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0');
      if(min>abs(X-753)) min = abs(X-753);
   }
   std::cout << min << std::endl;

   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;

vector<int> mapgen(int x){
    vector<int> enable;
    int mask = 1;
    for(int i =0; i < 6; i++){
        enable.push_back( ((x & mask) > 0) );
        mask <<= 1;
    }
    return enable;
}

int cnt(vector<vector<int>> map , vector<int> x_map, vector<int> y_map){
    int sum = 0;
    for(int y =0;  y < 6; y++){
        if(y_map[y] == 0){
            for(int x = 0; x < 6; x++){
                if(x_map[x] == 0)
                    sum += map[y][x];           
            }
        }
    }
    return sum;
}

int main(void){
    int H,W,K;
    cin >> H >> W >> K;

    vector<vector<int>> map;
    int sum = 0;

    int tableX[6] ,tableY[6];
  
    for(int i =0; i < 6; i++){
        vector<int> tmp = {0,0,0,0,0,0};
        if(i < H){
            for(int j = 0; j < W; j++){
                char tmp_c;
                cin >> tmp_c;
                int d = (tmp_c == '#')? 1: 0;
                tmp[j] = d;
                sum += d;
                tableX[j] += d;
                tableY[j] += d;
            }
        }
        map.push_back(tmp);
    }

    int pat = 0;

    for(int y =0; y < pow(2,H); y++){
        auto y_map = mapgen(y);
        for(int x =0; x < pow(2,W); x++){
            auto x_map = mapgen(x);
            int neko = cnt(map ,x_map, y_map);
            if(neko == K)
                pat++;
        }       
    }
    cout << pat << endl;
    return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int ans=1;
	for (int i = 1; i*i <= m; ++i)
	{
		if(m%i==0&&m/i>=n)
		{
			ans=max(ans,i);
			if(i>=n) ans=max(ans,m/i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll mod = 1e9+7;
typedef pair<int,int> P;
#define rep(i,N) for(int i=0;i<N;i++)
#define mm(n,m) memset(n,m,sizeof(n))

int main(){
    int n;
    cin>>n;
    ll h[n];
    rep(i,n)cin>>h[i];
    ll cnt = 0;
    ll ans = 0;
    rep(i,n-1){
        if(h[i]>=h[i+1]){
            cnt++;
           // cout<<"i:"<<i<<endl;
        }else{
            ans = max(ans,cnt);
            cnt = 0;
        }
    }
     ans = max(ans,cnt);
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
import statistics
import math

n = int(input())
a = [int(i) - (index+1) for index, i in enumerate(input().split())]

abs_total = 0
for i in a:
  abs_total += abs(i)

median = statistics.median(a) 


if n % 2 == 0 and median.is_integer() is False:
  median_high = statistics.median_high(a)
  median_low = statistics.median_low(a)

  abs_high = 0
  abs_low = 0
  for i in a:
    abs_high += abs(i-median_high)
    abs_low += abs(i-median_low)

  if abs_high < abs_low:
    print(int(abs_high))
  else:
    print(int(abs_low))
else:
  abs_total = 0
  for i in a:
    abs_total += abs(i-median)
  print(int(abs_total))



Measured memory_bytes: 27232
#marge sort マージソート ＋　転倒数
n = int(input())
a = list(map(int, input().split()))
cnt = 0

def marge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = [0]*(n1+1) 
    R = [0]*(n2+1)
    #L[0,,,,,n1]とr[0,,,,n2]を生成
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = pow(10,10)
    R[n2] = pow(10,10)
    
    l = 0
    r = 0
    for k in range(left, right):
        if L[l] <= R[r]:
            A[k] = L[l]
            l += 1
        else:
            A[k] = R[r]
            r += 1
            cnt += n1 - l

def margeSort(A, left, right):
    if 2 <= right - left:
        mid = (left + right)//2
        margeSort(A, left, mid)
        margeSort(A, mid, right)
        marge(A, left, mid, right)
    
        
margeSort(a, 0, len(a))
print(cnt)


Measured memory_bytes: 27476
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;
using ll = long long;

ll n;
ll dat[3 * 100005];
ll forward_part[3 * 100005];
ll backward_part[3 * 1000005];

priority_queue<ll> max_heap;
priority_queue<ll, vector<ll>, greater<ll> > min_heap;

int main()
{
	ll ans = -1 * (1ll << 60ll);

	cin >> n;
	for (ll i = 1; i <= 3 * n; i++) {
		cin >> dat[i];
	}

	for (ll i = 1; i <= 2 * n; i++) {
		forward_part[i] = forward_part[i - 1] + dat[i];
		min_heap.push(dat[i]);

		if (i > n) {
			forward_part[i] = forward_part[i] - min_heap.top();
			min_heap.pop();

		}
	}

	for (ll i = 3 * n; i >= n; i--) {
		backward_part[i] = backward_part[i + 1] + dat[i];
		max_heap.push(dat[i]);

		if (i <= 2 * n) {
			backward_part[i] = backward_part[i] - max_heap.top();
			max_heap.pop();

		}
	}

	/*
	for (ll i = 1; i <= 3 * n; i++) {
		printf("%lld : %lld\n", forward_part[i], backward_part[i]);
	}
	*/

	for (ll i = n; i <= 2 * n; i++) {
		ans = max(ans, forward_part[i] - backward_part[i + 1]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 10868
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int n;
  cin>>n;
  rep(i,n){
    string ord,s;
    cin>>ord;
    cin>>s;
    int len=s.size();
    for(j=ord.size()-1;j>=0;j--){
      if(ord[j]=='C'){
	string tmp="";
	tmp.push_back(s[0]);
	s.erase(s.begin());
	s+=tmp;
      }else if(ord[j]=='J'){
	string tmp="";
	tmp.push_back(s[len-1]);
	s.erase(s.end()-1);
	s=tmp+s;
      }else if(ord[j]=='A'){
	reverse(all(s));
      }else if(ord[j]=='E'){
	rep(k,len/2)
	  swap(s[k],s[(len+1)/2+k]);
      }else if(ord[j]=='M'){
	rep(k,len)
	  if(s[k]<='8' && s[k]>='0')s[k]++;
	  else if(s[k]=='9')s[k]='0';
      }else{
	rep(k,len)
	  if(s[k]<='9' && s[k]>'0')s[k]--;
	  else if(s[k]=='0')s[k]='9';
      }
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 3080
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

std::string s;
long cnt = 0;
long pos = 0;

int main(){
    std::cin >> s;
    if(s[0] != 'A' || s[1] < 'a' || s[1] > 'z'){
        printf("WA\n");
        return 0;
    }
    for(int i = 2; i < s.length() - 1; i++){
        if(s[i] == 'C'){
            pos = i;
        }
    }
    if(pos == 0){
        printf("WA\n");
        return 0;
    }
    for(int i = 2; i < s.length(); i++){
        if(i != pos && (s[i] < 'a' || s[i] > 'z')){
            printf("WA\n");
            return 0;
        }
    }
    printf("AC\n");
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
int n, m;
vector<int> c, x;
LL dp[20005][550];
/**********************************************/

signed main(){
    while(cin >> n >> m, n != 0 || m != 0){
        c.resize(m);
        x.resize(n);
        REP(i, m) cin >> c[i];
        REP(i, n) cin >> x[i];

        REP(i, 20005) REP(j, 550) dp[i][j] = INF;
        dp[0][128 + 255] = 0;
        FOR(i, 1, n+1){
            for(int j = 0; j <= 255; j++){
                bool flag = false;
                if(j == 0){
                    REP(k, m){
                        for(int z = 0 - c[k]; z >= 0; z--){
                            if(dp[i-1][z + 255] != INF){
                                dp[i][0 + 255] = min(dp[i][0 + 255], dp[i-1][z + 255] + (LL)pow(abs(x[i-1] - (0)), 2));
                            }
                        }
                    }
                }else if(j == 255){
                    REP(k, m){
                        for(int z = 255 - c[k]; z <= 255; z++){
                            if(dp[i-1][z + 255] != INF){
                                dp[i][255 + 255] = min(dp[i][255 + 255], dp[i-1][z + 255] + (LL)pow(abs(x[i-1] - (255)), 2));
                            }
                        }
                    }
                }else{
                    REP(k, m) flag |= dp[i-1][j-c[k] + 255] != INF;
                    if(flag){
                        REP(k, m){
                            if(j-c[k] >= 0 && j-c[k] <= 255 && dp[i-1][j-c[k] + 255] != INF){
                                dp[i][j + 255] = min(dp[i][j + 255], dp[i-1][j-c[k] + 255] + (LL)pow(abs(x[i-1] - j), 2));
                                //cout << i << " " << dp[i][j + 255] << " " << x[i-1] << " " << j-c[k] << endl;
                            }
                        }
                    }
                }
            }
        }

        LL ans = INF;
        for(int i = 0; i <= 255; i++) ans = min(ans, dp[n][i + 255]);
        cout << ans << endl;
    }

}



Measured memory_bytes: 89124
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

void aprint(int a[51][51],  int h, int w)
{
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(a[i][j] == -3){
	cout << " ";
      } else if(a[i][j] == -1){
	cout << "W";
      } else if(a[i][j] == -2){
	cout << "B";
      } else if(a[i][j] == 1){
	cout << "*";
      } else if(a[i][j] == 2){
	cout << "+";
      } else {
	cout << "-";
      }
    }
    cout << endl;
  }
  cout << endl;

  return ;
}

void search(char a[51][51], int c[51][51], int h, int w, int s, int t, int v, char p)
{
  if(a[s][t] == p){
    // c[s][t] = -v;
    return ;
  } else if(a[s][t] != '.' || c[s][t] < 0 || c[s][t] == v){
    return ;
  }
  c[s][t] = (c[s][t] > 0)? -3 : v;

  if(s > 0){
    search(a, c, h, w, s-1, t, v, p);
  }
  if(s < h-1){
    search(a, c, h, w, s+1, t, v, p);
  }
  if(t > 0){
    search(a, c, h, w, s, t-1, v, p);
  }
  if(t < w-1){
    search(a, c, h, w, s, t+1, v, p);
  }

  return ;
}

void func(char a[51][51], int c[51][51], int h, int w, char p, int s, int t)
{
  int v = (p == 'W')? 1 : 2;

  if(s > 0){
    search(a, c, h, w, s-1, t, v, p);
  }
  if(s < h-1){
    search(a, c, h, w, s+1, t, v, p);
  }
  if(t > 0){
    search(a, c, h, w, s, t-1, v, p);
  }
  if(t < w-1){
    search(a, c, h, w, s, t+1, v, p);
  }

  return ;
}

int main(int argc, char **argv)
{
  int w, h, c[51][51], cw, cb;
  char a[51][51];

  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0){
      break;
    }
    fill(&c[0][0], &c[h][w], 0);

    for(int i = 0; i < h; i++){
      scanf("%s", a[i]);
    }

    cw = cb = 0;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(c[i][j] == 0 && a[i][j] != '.'){
	  func(a, c, h, w, a[i][j], i, j);
	}
      }
    }
    // aprint(c, h, w);
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(c[i][j] == 1){
	  cw++;
	} else if(c[i][j] == 2){
	  cb++;
	}
      }
    }

    cout << cb << " " << cw << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,m,k,l,c,f;
	cin>>n>>m;
	vector<string>s(n+1);
	for(i=1;i<=n;i++)cin>>s[i];
	vector<vc>dp((n+1),vc(m+1,0));
	string ss;j=1;
	while(s[1][j-1]=='.')
	    dp[1][j++]=1;
	for(i=2;i<=n;i++)
	{
	    //ss=s[i];
	    for(j=1;j<=m;j++)
	    {
	        if(s[i][j-1]=='.')
	            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
	        else dp[i][j]=0;
	    }
	}cout<<dp[n][m]<<"\n";
	/*for(i=1;i<=n;i++)
	{
	    for(j=1;j<=m;j++)cout<<dp[i][j]<<" ";
	    cout<<"\n";
	}*/
	return 0;
}


Measured memory_bytes: 12128
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int N;cin>>N;
    VI P(N);
    REP(i,N)
    {
        cin>>P[i];
    }
    int n=0;
    string ans;
    REP(i,N)
    {
        if (i+1!=P[i])n++;
    }
    if (n==0||n==2)ans="YES";
    else ans="NO";
    cout<<ans<<endl;
    return 0;
}



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

int main()
{
  int n,m;
  int l,r;
  l=0;r=99999999;
  cin >> n >> m;

  for(int i=0;i<m;i++)
  {
    int buf_l,buf_r;
    cin >> buf_l >> buf_r;
    if(l<buf_l)
      l = buf_l;
    if(r>buf_r)
      r = buf_r;
  }
  r=r-l+1;
  if(r<0)
    r = 0;
  cout << r << endl;
  return 0;
}

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

int main(){
	
	int a,b,c,count=0;
	cin >> a >> b >> c;
	int tempa,tempb,tempc;
	set<tuple<int,int,int> > s;
	tuple<int, int, int> triple;
	while (true) {
		if (a%2!=0 || b%2 != 0|| c%2!=0) {
			cout << count;
			break;
			}
		
		tempa=a;tempb=b;tempc=c;
		a = tempb/2 + tempc/2;
		b = tempa/2 + tempc/2;
		c = tempa/2 + tempb/2;
		if (s.count(make_tuple(a,b,c))){
			cout << -1;
			break;}
		count ++;
		s.emplace(a,b,c);
		}
}


Measured memory_bytes: 256
def prime(x):
    flag = True
    n = 1
    while(n**2 <=x):
        n += 1
        q,r = divmod(x,n)
        if r==0:
            flag = False
            break
    return flag

def find(x):
    c = x
    while(prime(c)==False):
        c +=2
    return c


x = int(input())
if x==2:
    print(x)
elif x%2==0:
    print(find(x+1))
else:
    print(find(x))

Measured memory_bytes: 3064
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
A=get_i
B=get_i
r=0
N.times do|i|
  r+=max(0,A[i]-B[i])
end
N.times do|i|
  if A[i]<B[i]
    r-=(B[i]-A[i])/2
  end
  break if r<=0
end
puts yn_judge(r<=0)

Measured memory_bytes: 15552
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X, Y, Z;
  scanf("%d %d %d", &X,&Y,&Z);
  
  int i = 0;
  while(((Y+Z)*i+Z) <= X){
    i++;
  }
  cout << i-1;    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h> 
int main()
{
	char a[200]={0};
	int i,l,ans;
	scanf("%s",a);
	l=strlen(a);
	if(l%2==1)
	{
		ans=0;
		for(i=1;i<=l/2;i++)
		{
			if(a[(l/2)-i]!=a[(l/2)+i])
			ans++;
		}
	}
	else 
	{
		ans=0;
		for(i=0;i<l/2;i++)
		{
			if(a[(l/2)-1-i]!=a[(l/2)+i])
			ans++;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 110;
int t,n;
int a[MAX],b[MAX];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    cout<<(n^1)<<endl;
    return ~~(0^0);
}


Measured memory_bytes: 3644
n=int(input())
a=list(map(int,input().split()))
dp=[[0 for i in range(n+1)] for j in range(n+1)]

for len in range(1,n+1):
  for i in range(n+1):
    if i+len>n:
      break
    j=i+len
    if (n - len) % 2 == 0:
      dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
      #print(len,dp)
    else:
      dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])
      #print(len,dp)
print(dp[0][n])

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) cin >> d[i];

  sort(d.begin(), d.end());

  int mochi = d[0];
  int ans = 1;

  for (int i = 1; i < N; i++) {
    if (d[i] > mochi) {
      ans++;
      mochi = d[i];
    }
  }

  cout << ans << endl;
}

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, k;

int main() {
    cin >> n >> k;
    V<Pll> v(n);
    REP(i, n) {
        ll t, d; cin >> t >> d;
        v[i] = {d, t};
    }

    sort(ALL(v), greater<Pll>());

    ll D = 0, T = 0;
    M<ll, Pll> m;
    V<Pll> dup;
    REP(i, k) {
        ll d = v[i].first, t = v[i].second;
        if (m.count(t) == 0) {
            m[t] = v[i];
            T++;
        } else {
            dup.push_back(v[i]);
        }
        D += d;
    }
    sort(ALL(dup), greater<Pll>());

    ll maxi = T*T + D;

    REP2(i, k, n) {
        if (dup.empty()) break;
        if (m.count(v[i].second) != 0) continue;
        Pll mini = dup.back();
        dup.pop_back();
        m[v[i].second] = v[i];
        T++;
        D -= mini.first - v[i].first;
        maxi = max(maxi, T*T + D);
    }
    cout << maxi << '\n';

    return 0;
}


Measured memory_bytes: 6648
#include <stdio.h>
int main(void){
 int a,b,c,i;
 
 scanf("%d%d%d",&a,&b,&c);
 
 for(i=0;i<c;i++){
     if(i%2==0){
     if(a%2!=0){
         a-=1;
     }
     b=b+a/2;
     a=a-a/2;
     }else{
          if(b%2!=0){
         b-=1;
     }
     a=a+b/2;
     b=b-b/2;
     }
     }
     printf("%d %d",a,b);
 return 0;
}

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

#define fst first
#define snd second
#define mp make_pair
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define per(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()

template <typename T1, typename T2>
bool umin(T1 &x, const T2 &y) {return (x>y ? (x=y,true):false);}
template <typename T1, typename T2>
bool umax(T1 &x, const T2 &y) {return (x<y ? (x=y,true):false);}

template <typename T>
void read(T& x) {
    char ch;
    T p = 1; x = 0;
    do {ch = getchar();} while(ch <= ' ');
    if (ch == '-') p = -1, ch = getchar();
    while (ch>='0' && ch<='9') x = x*10 + ch-'0', ch = getchar();
    x *= p;
}

void read(string& x) {
    char ch;
    do {ch = getchar();} while (ch <= ' ');
    while (ch > ' ') x += ch, ch = getchar();
}

void read(char& x) {do {x = getchar();} while (x <= ' ');}
template<typename T, typename... R>
void read(T& x, R&... y) { read(x); read(y...); }

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = (int)2e5+3;
const int INF = (int)1e9+17;
const ll mod = (ll)1e9+7;
const ll LLINF = (ll)1e18+17;
const ld pi = (ld)acos(-1.0);


int n, m;
int a[N];


ll solve(int mask) {
    if (__builtin_popcount(mask) != m) return LLINF;
    ll last = -1;
    ll ret = 0;
    vector<ll> b;
    rep(i, 0, n) {
        bool bit = (mask>>i)&1;
        if (bit) {
            if (last != -1) ret += max<ll>(0, last-a[i]+1);
            last = max<ll>(last+1, a[i]);
            b.push_back(last);
        } else b.push_back(a[i]);
    }
    ll pref = 0;
    rep(i, 0, n) {
        bool bit = (mask>>i)&1;
        if (bit && pref >= b[i]) return LLINF;
        umax(pref, b[i]);
    }
    return ret;
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    read(n, m);
    rep(i, 0, n) read(a[i]);
    ll res = LLINF;
    rep(mask, 0, (1<<n)) umin(res, solve(mask));
    printf("%lld\n", res);

    return 0;
}


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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)
#define	INF (1<<29)
//536870912

#define	MOD 1000000007

int	main() {
	string S;
	cin >>S;
	string SS;
	for (int i=0; i<S.size(); i++) {
		char C=S.at(i);
		if (('B'==C)&&(i<S.size()-1)&&('C'==S.at(i+1))) {
				i++;
				C='D';
		}
		SS.push_back(C);
	}
	S=SS;
	int i=0;
	long N=0;
	long st=0;
	while(i<S.size()) {
		if ('A'==S.at(i)) {
			st++;
		} else if ('D'==S.at(i)) {
			// A-D
			N +=st;
			// st=st;
		} else { 
			// B or C
			st=0;
		}
		i++;
	}
	cout <<N <<endl;
	return 0;
}



Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int a,b,c;
           cin>>a>>b>>c;
           Yes((a-c)*(b-c)<0);
}

Measured memory_bytes: 3560
import java.util.*;

public class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            if(n==0) break;
            int max = 0;
            int min = Integer.MAX_VALUE;
            for(int i=0; i<n; i++){
                int sum = 0;
                for(int j=0; j<5; j++) sum += sc.nextInt();
                max = Math.max(max, sum);
                min = Math.min(min, sum);
            }

            System.out.println(max+" "+min);
        }
    }

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

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

int main() {
  int n,m;
  cin>>n>>m;
  
  vector<int> x(m);
  for(int i=0; i<m; i++) cin >> x[i];
  
  sort(x.begin(),x.end());
  
  int ans=x[m-1]-x[0];
  
  if(m==1) cout<<ans<<endl;
  else{
    vector<int> dif(m-1);
    for(int i=0; i<m-1; i++) dif[i]=x[i+1]-x[i];
  
    sort(dif.begin(),dif.end());
    reverse(dif.begin(),dif.end());
  
    for(int i=0; i<n-1 && i<m; i++){
      ans-=dif[i];
    }
    
    cout<<ans<<endl;
  }
}

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

using namespace std;

int n;
int a[100002];

int main(){
    cin >> n;
    a[0] = 0;
    int x = 0;
    int amount = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        amount += abs(x - a[i]);
        x = a[i];
    }
    amount += abs(x);

    //cout << amount << endl;
    a[n + 1] = 0;

    for (int i = 1; i <= n; ++i) {
        int tmp = abs(a[i - 1] - a[i]) + abs(a[i + 1] - a[i]);
        int shortcut = abs(a[i + 1] - a[i - 1]);
        cout << amount - (tmp - shortcut) << endl;
    }
}

Measured memory_bytes: 2168
#include <iostream>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;
typedef long long ll;

ll N, A, B, C, D;

int main(void) {
  cin >> N >> A >> B >> C >> D;

  bool f = false;
  REP(i, 0, N) {
    if(C * (N - 1 - i) - D * i <= B - A && B - A <= -C * i + D * (N - 1 - i)) {
      f = true;
    }
  }

  cout << (f ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

/*------------------------------------------------*/

int main(){
  int w, h, n;
  cin >> w >> h >> n;
  vector<vector<int>> rec(w, vector<int>(h));
  rep(i,n) {
    int x, y, a;
    cin >> x >> y >> a;
    if(a == 1){
      rep(i,x)rep(j,h) rec[i][j] = 1;
    }
    else if(a == 2){
      for(int i = x; i < w; i++)rep(j,h) rec[i][j] = 1;
    }
    else if(a == 3){
      rep(i,w)rep(j,y) rec[i][j] = 1;
    }
    else if(a == 4){
      rep(i,w)for(int j = y; j < h; j++) rec[i][j] = 1;
    }
  }
  int ans = 0;
  rep(i,w)rep(j,h){
    if(rec[i][j] == 0) ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int zoro = 0, max = 0;
		for(int i = 0; i < N; i++) {
			if(sc.nextInt() == sc.nextInt())
				zoro++;
			else
				zoro = 0;
			max = Math.max(zoro, max);
		}
		System.out.println(max >= 3 ? "Yes" : "No");
	}

}


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

int main() {
  set<int> SE;
  int A, B, K;
  cin >> A >> B >> K;
  int a = A, b = B;
  for (int i = 0; i < K; i++) SE.insert(a++), SE.insert(b--);
  for (auto se : SE) if (se >= A && se <= B) cout << se << "\n";
}


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

int main(){
    int n;
    cin >> n;
    string s[n];
    int p[n];
    rep(i, n){
        cin >> s[i] >> p[i];
    }
    rep(i, n){
        p[i] = 100 - p[i];
    }

    // rep(i, n){
    //     printf("%d\n", v[i].first);
    // }
    
    vector <pair <string, int>> v, v_;

    rep(i, n){
        v.emplace_back(make_pair(s[i], p[i]));
    }
    v_ = v;
    sort(v.begin(), v.end());
    rep(i, n){
        rep(j,n){
            if(v[i].first==v_[j].first && v[i].second == v_[j].second){
                printf("%d\n", j+1);
            }
        }
    }
      return 0;
}

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

int main(int argc, char const *argv[]) {
  string w;
  cin >> w;
  int table[26] = {};
  for(int i = 0; i < w.size(); i++){
    table[w[i] - 'a']++;
  }
  for(int i = 0; i < 26; i++){
    if(table[i] % 2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)
#define SZ(a) int((a).size())

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

template <typename T>
using V = std::vector<T>;
template <typename T>
vector<T> make_vec(size_t n, T a) {
  return vector<T>(n, a);
}
template <typename... Ts>
auto make_vec(size_t n, Ts... ts) {
  return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}

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

  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  for (int start = 0; start < n; ++start) {
    const int m = n - start;
    V<int> Z(m);
    Z[0] = n;
    int i = 1, j = 0;
    while (i < m) {
      while (start + i + j < n && s[start + j] == s[start + i + j]) j++;
      Z[i] = j;

      if (j == 0) {
        i++;
        continue;
      }
      int k = 1;
      while (k < j && k + Z[k] < j) {
        Z[i + k] = Z[k];
        k++;
      }
      i += k;
      j -= k;
    }
    for (int k = 1; k < m; ++k) {
      chmax(ans, min(Z[k], k));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <cctype>
#include <utility>
#include <map>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//void scan(string &s) {int c;do{c=gcu();s+=c;}while(!(c=='\n'||c==' '));}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	float w;
	map<float, string> Class = {
		{48.00, "light fly"}, {51.00, "fly"}, {54.00, "bantam"}, {57.00, "feather"},
		{60.00, "light"}, {64.00, "light welter"}, {69.00, "welter"}, {75.00, "light middle"},
		{81.00, "middle"}, {91.00, "light heavy"}, {1.0e5, "heavy"}};
	while (scanf("%f", &w) != EOF)
		out((*Class.lower_bound(w)).second, '\n');
}


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

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

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

using namespace std;

int n, m, d;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m >> d;

    if (d == 0) cout << fixed << setprecision(9) << (double)(m - 1) / (double)n;
    else cout << fixed << setprecision(9) << (double)(1LL * 2 * (m - 1) * (n - d)) / (double)(1LL * n * n);
    return 0;
}

//d = 0 => (m - 1) / n
//n = 5, m = 4, d = 1 => 24/25
//n = 5, m = 4, d = 2 => 18/25
//n = 5, m = 4, d = 3 => 12/25
//n = 5, m = 4, d = 4 => 6/25
//n = 5, m = 3, d = 1 => 16/25
//n = 5, m = 3, d = 2 => 12/25
//n = 5, m = 3, d = 3 => 8/25
//n = 5, m = 3, d = 4 => 4/25
//n = 5, m = 2, d = 1 => 8/25
//n = 5, m = 2, d = 2 => 6/25
//n = 5, m = 2, d = 3 => 4/25
//n = 5, m = 2, d = 4 => 2/25
//n = 6, m = 4, d = 1 => 5/6
//2(m - 1)(n - d) / n ^ 2


Measured memory_bytes: 256