akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<pair<int, int>> ab(n); REP(i, n) cin >> ab[i].second >> ab[i].first;
  sort(ALL(ab));
  reverse(ALL(ab));
  vector<pair<int, int>> cd(n); REP(i, n) cin >> cd[i].first >> cd[i].second;
  sort(ALL(cd));
  int ans = 0;
  REP(i, n) REP(j, ab.size()) {
    if (ab[j].second < cd[i].first && ab[j].first < cd[i].second) {
      ++ans;
      ab.erase(ab.begin() + j);
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

int main(int argc, const char * argv[]) {
    int a,b,n;
    string s;
    cin>>n>>a>>b>>s;
    int all=a+b;
    
    for (int i=0; i<n; i++) {
        if (s[i]=='a') {
            if (all>0) {
                all--;
                cout<<"Yes"<<endl;
                continue;
            }
        }
        if (s[i]=='b') {
            if (all>0 && b>0) {
                all--;
                b--;
                cout<<"Yes"<<endl;
                continue;
            }
        }
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 896
#include <iostream>

int main(){
    int n;
    int a[100010];
    std::cin >> n;
    a[0] = 0;
    a[n+1] = 0;
    int total = 0;
    for(int i = 0; i < n; i++){
        std::cin >> a[i+1];
        total += std::abs(a[i]-a[i+1]);
    }
    total += std::abs(a[n]);
    for(int i = 0; i < n; i++){
        std::cout << total - std::abs(a[i]-a[i+1]) - std::abs(a[i+1]-a[i+2]) + std::abs(a[i]-a[i+2]) << std::endl;
    }
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define pii std::pair <int, int>

pii calc(int a, int b){
	int y = (b + a - 1) / a * 3;
	int x = (a - 1) * y - 1;
	return {x, -y};
}

int H, W, h, w;

int main(){
	scanf("%d%d%d%d", &H, &W, &h, &w);
	if (H % h){
		pii p = calc(h, H);
		printf("Yes\n");
		for (int i = 0; i < H; ++ i){
			for (int j = 0; j < W; ++ j){
				printf("%d%c", i % h ? p.second : p.first, " \n"[j == W - 1]);
			}
		}
	}
	else{
		if (W % w){
			pii p = calc(w, W);
			printf("Yes\n");
			for (int i = 0; i < H; ++ i){
				for (int j = 0; j < W; ++ j){
					printf("%d%c", j % w ? p.second : p.first, " \n"[j == W - 1]);
				}
			}
		}
		else{
			return printf("No\n"), 0;
		}
	}
	for (int i = 0; i < H; ++ i){
		for (int j = 0; j < W; ++ j){
		}
	}
	return 0;
}

Measured memory_bytes: 1280
implicit none
integer(8):: n, i, ans, k, x, y, z, j
integer(8),allocatable,dimension(:):: a,b,c,d,e

read (5,*) x,y,z,n

allocate(a(x))
allocate(b(y))
allocate(c(z))
allocate(d(x*y))
allocate(e(min(x*y, 3000) * z))

d = 0
e = 0
read(5,*) (a(i),i=1,x)
read(5,*) (b(i),i=1,y)
read(5,*) (c(i),i=1,z)


do i = 1, x
    do j = 1, y
        d( (i-1) * y + j ) = a(i) + b(j)
    enddo
enddo

call heapsort(x,c)
call heapsort(x*y,d)


do i = x*y, max(x*y-3000+1, 1), -1
    do j = 1, z
        e((x*y-i) * z + j ) = d(i) + c(j)
    enddo
enddo
 
 
call heapsort(min(x*y, 3000) * z, e)

do i = min(x*y, 3000) * z,  min(x*y, 3000) * z - n +1, -1
    write(6,*) e(i)
enddo
 
 

end
 
!---http://slpr.sakura.ne.jp/qp/sortf90/---
subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    double precision,intent(inout) :: array(1:n)
 
    integer ::i,k,j,l
    double precision :: t
 
    if(n.le.0)then
        write(6,*)"Error, at heapsort"; stop
    endif

    if(n.eq.1)return 
        l=n/2+1
        k=n
        do while(k.ne.1)
            if(l.gt.1)then
                l=l-1
                t=array(L)
            else
                t=array(k)
                array(k)=array(1)
                k=k-1
                if(k.eq.1) then
                    array(1)=t
                    exit
                endif
            endif
            i=l
            j=l+l
            do while(j.le.k)
                if(j.lt.k)then
                    if(array(j).lt.array(j+1))j=j+1
                endif
                if (t.lt.array(j))then
                    array(i)=array(j)
                    i=j
                    j=j+j
                else
                    j=k+1
                endif
            enddo
            array(i)=t
    enddo
    return
end subroutine heapsort

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

// ref : https://atcoder.jp/contests/agc022/submissions/10229377

int a[2][8]={
    {2,10,3,9,4,8,6,12},
	{6,2,10,3,9,4,8,12}
};

int main(){
    int n;
    cin >> n;
    if (n == 3){
        cout << 2 << " " << 5 << " " << 63 << endl;
        return 0;
    }
	rep(i, n){
        cout << a[n&1][i&7] << " ";
        a[n&1][i&7] += 12;
	}
    cout << endl;
    return 0;
}


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

using namespace std;

#define ll long long 
#define REPL(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
static const int MAX = 10010;
static const ll INFTY = 1e12;
static const ll NUMMAX = 1000000007;
static const ll MOD = 1000000007;
 #define LOOP 10000000

int main() {

    ll N, A, B, ans;
    ll diffR, diffL, tmp;
    
    cin >> N >> A >> B;

    if( (B-A) % 2 == 0 ){
        ans = (B-A) / 2;
    } else {
        if((A - 1) < (N - B)){
            ans = A - 1;
            A -= ans;
            B -= ans;
            ans += ( B / 2 );
        }else {
            ans = N - B;
            A += ans;
            B += ans;
            ans += ( N + 1 - A ) / 2;
        }
    }

   cout << ans << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

using namespace std;
//using std::cin, std::cout, std::endl, std::string;
using ll = long long;

#define rep(countName, left, right, up) for (auto countName = left; countName < right; countName += up)
#define REP(countName, end) for (auto countName = 0; countName < end; countName++)
#define rev(countName, right, left, down) for (auto countName = right; countName >= left; countName -= down)
#define REV(countName, end) for (auto countName = end; countName >= 0; countName--)

auto solve1(string a, string b)
{
    int n = std::stoi(a + b);
    for (auto i = 1; i * i <= n; i++)
    {
        if (i * i == n)
        {
            return "Yes";
        }
    }
    return "No";
}

int main(void)
{
    string a, b;
    cin >> a >> b;
    cout << solve1(a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 500010
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define int long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int n, m, ans, k, cnt;
const int mod = 1e9 + 7;
int t[SIZE], a[SIZE];
int pos[SIZE]; //离散化
struct Node {
	int val;
	int id;
	bool operator< (const Node& b) {
		return (val < b.val) || (val == b.val && id < b.id);
	}
}p[SIZE], tp[SIZE];
int lowbit(int x) { return x & (-x); }
void add(int pos, int x) {
	for (; pos <= n; pos += lowbit(pos)) {
		t[pos] += x;
	}
}

int query_presum(int pos) {
	int ans = 0;
	for (; pos > 0; pos -= lowbit(pos)) {
		ans += t[pos];
	}
	return ans;
}

signed main() {
	io(); cin >> n >> k;
	rep(i, 1, n) cin >> p[i].val, p[i].id = i;
	rep(i, 1, n) tp[i] = p[i];
	sort(p + 1, p + 1 + n);
	rep(i, 1, n) pos[p[i].id] = i;
	rep(i, 1, n) {
		add(pos[i], 1);
		ans += i - query_presum(pos[i]);
	}
	int K = k;
	k = (k * (k - 1ll)) / 2 % mod;
	rep(i, 1, n) {
		rep(j, 1, n) {
			if (tp[i].val > tp[j].val) {
				++cnt;
			}
		}
	}
	cout << (ans * K % mod + cnt * k) % mod;
}

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

using namespace std;

int main(){
  string s;
  cin >> s;
  char c='a';
  for(int i=0; i<26; i++){
      for(int j=0; j<s.size(); j++){
          if(s.at(j) == c)
          break;
          if(j == s.size()-1){
              cout << c;
              return 0;
          }
      }
      c++;
  }
  cout << "None";
}

Measured memory_bytes: 512
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

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

fn main() {
    let v = read_vec::<i128>();
    let (n, k) = (v[0] as usize, v[1]);
    let p = read_vec::<usize>()
        .into_iter()
        .map(|x| x - 1)
        .collect::<Vec<_>>();
    let c = read_vec::<i128>();

    let d_max = 31;
    let mut next_pos = vec![vec![0; n]; d_max];

    for i in 0..n {
        next_pos[0][i] = p[i];
    }

    for di in 1..d_max {
        for i in 0..n {
            next_pos[di][i] = next_pos[di - 1][next_pos[di - 1][i]];
        }
    }
    let mut next_score = vec![vec![0; n]; d_max];
    for i in 0..n {
        next_score[0][i] = c[p[i]];
    }
    for di in 1..d_max {
        for i in 0..n {
            let mid_pos = next_pos[di - 1][i];
            next_score[di][i] = next_score[di - 1][mid_pos] + next_score[di - 1][i];
        }
    }
    let mut ans = *c.iter().min().unwrap();
    for i in 0..n {
        let mut temp = 0;
        let mut smax = max(0, k - n as i128);
        let mut cur_pos = i;
        for di in (0..d_max).rev() {
            if smax >= (1 << di) {
                smax -= 1 << di;
                temp += next_score[di][cur_pos];
                cur_pos = next_pos[di][cur_pos];
            }
        }
        for i in 0..n {
            smax += 1;
            temp += next_score[0][cur_pos];
            cur_pos = next_pos[0][cur_pos];
            ans = max(temp, ans);
            if smax == k {
                break;
            }
        }
    }

    let mut search_max = n + 1;
    if k < search_max as i128 {
        search_max = k as usize;
    }
    //assert!(next_score[1].iter().max().unwrap() >= next_score[0].iter().max().unwrap());
    for kk in 1..search_max + 1 {
        for i in 0..n {
            let mut temp = 0;
            let mut kk = kk;
            let mut cur_pos = i;
            for di in (0..d_max).rev() {
                if kk >= (1 << di) {
                    kk -= 1 << di;
                    temp += next_score[di][cur_pos];
                    cur_pos = next_pos[di][cur_pos];
                }
            }
            assert_eq!(kk, 0);
            ans = max(temp, ans);
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 5876
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <math.h>
#include <numeric>
#include <algorithm>
#include <string>
#include <tuple>

typedef long long ll;

using namespace std;



int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> vs(n);
    for(int i=0; i<n; ++i){
        vs[i] = s[i] - '0';
    }
    vector<pair<int, int> > lft;
    lft.push_back(make_pair(0, 0));
    for(int i=0; i<n; ++i){
        auto l = 0;
        if(vs[i]==0){
            l=i;
            while( (vs[i]==0)&(i<n)) ++i;
            lft.push_back(make_pair(l, i));
        }
    }
    lft.push_back(make_pair(n, n));
    int ret = 0;
    
    if(k>=lft.size()-2){
        ret = n;
    }else{
        for (int i=0; i<lft.size()-k-1; ++i){
            ret = max(ret, lft[i+k+1].first - lft[i].second);
        }
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 1404
def getlist():
	return list(map(int, input().split()))

def main():
	N = int(input())
	p = getlist()
	a = [N * i for i in range(1, N + 1)]
	b = [N * (N - i) for i in range(N)]
	for i in range(N):
		a[p[i] - 1] += i
	print(" ".join(list(map(str, a))))
	print(" ".join(list(map(str, b))))

if __name__ == '__main__':
	main()

Measured memory_bytes: 44824
/*
* author: pavveu
*/

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

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int,int>;
using graph = vector<vi>;

#define FOR(name__, upper__) for (int name__ = 0; name__ < (upper__); ++name__)
#define all(x) begin(x), end(x)
#define mp make_pair
#define mt make_tuple

template<class T>
void initialize_matrix(vector<vector<T>>& matrix, int rows, int cols, T value) {
	assert(matrix.empty());
	FOR (row, rows) 
		matrix.emplace_back(cols, value);
}

struct segment_tree {
    int N; ll mod;
    vi lo, hi;
    vll delta, dec_sum;
	vll pow10, base;

    segment_tree(int n, ll p) : N(4*n + 1), mod(p), lo(N, -1), hi(N, -1), delta(N, -1), dec_sum(N, 0), pow10(N, 1), base(N, 0) {
		for(int i = 1; i < N; i++) {
			pow10[i] = pow10[i - 1] * 10 % mod;
			base[i] = (pow10[i - 1] + base[i - 1]) % mod;
		}
        init(0, n - 1);
    }

    void init(int a, int b, int i = 1) {
        lo[i] = a; hi[i] = b; 

        if ( a == b ) return;

        int m = (a+b)/2;
        init(a, m, 2*i);
        init(m + 1, b, 2*i + 1);
    }

	int size(int i) {
		return (hi[i] - lo[i] + 1);
	}

    void propagate(int i) {
		if ( delta[i] != -1 ) {
			delta[2*i] = delta[i];
			delta[2*i + 1] = delta[i]; 
			delta[i] = -1;
		}
    }

    void update(int i) {
		ll left = 0;
		if ( delta[2*i] == -1 ) {
			left = dec_sum[2*i];  
		}
		else {
			left = base[ size(2*i) ] * delta[2*i] % mod;
		}

		ll right = 0;
		if ( delta[2*i + 1] == -1 ) {
			right = dec_sum[2*i + 1];  
		}
		else {
			right = base[ size(2*i + 1) ] * delta[2*i + 1] % mod;
		}

		dec_sum[i] = (left * pow10[ size(2*i+1) ] + right) % mod;
    }

    void set_range(int a, int b, ll val, int i = 1) {
		
        if ( b < lo[i] || hi[i] < a ) {
			return; 
		}
        else if ( a <= lo[i] && hi[i] <= b ) {
            delta[i] = val;
            return;
        }

        propagate(i);
        set_range(a, b, val, 2*i);
        set_range(a, b, val, 2*i + 1);
        update(i);
    }

    ll query(int a, int b, int i = 1) {
        if ( b < lo[i] || hi[i] < a ) return 0ll;
        else if ( a <= lo[i] && hi[i] <= b ) {
			if ( delta[i] != -1) {
            	return delta[i] * base[ size(i) ] % mod;
			}
			else {
				return dec_sum[i];
			}
        }

        propagate(i);
        ll left_sum = query(a, b, 2*i);
        ll right_sum = query(a, b, 2*i + 1);
        update(i);

		return (left_sum * pow10[size(2*i + 1)] + right_sum) % mod;
    }
};


void go() {
	ll mod = 998'244'353ll;
	int n, q;
	cin >> n >> q;

	segment_tree st(n, mod);

	st.set_range(0, n - 1, 1);

	while (q--) {
		int a, b, d;
		cin >> a >> b >> d;
		st.set_range(a - 1, b - 1, d);
		cout << st.query(0, n - 1) << "\n";
	}
}

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

	go();

	return 0;
}


Measured memory_bytes: 34620
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

string s[3];
int a, x[3];
int main() {
    cin >> s[0] >> s[1] >> s[2];
    for (; x[a] - s[a].size();) {
        a = s[a][x[a]++] - 'a';
    }
    cout << char('A' + a) << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a*n, b) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

typedef struct asumisu_tag {
	int ayaneru;
	struct asumisu_tag *hanazawakana;
	struct asumisu_tag *tamurayukari;
} asumisu;

asumisu* kitaeri(void) {
	asumisu* kugyu = malloc(sizeof(asumisu));
	int hayaminn;
	if (kugyu == NULL) exit(1);
	while ((hayaminn = getchar()) != '(') {
		if (hayaminn == EOF) exit(1);
	}
	hayaminn = getchar();
	if (hayaminn == '(') {
		ungetc('(', stdin);
		kugyu->hanazawakana = kitaeri();
		hayaminn = getchar(); assert(hayaminn == ')');
	} else {
		assert(hayaminn == ')');
		kugyu->hanazawakana = NULL;
	}
	hayaminn = getchar(); assert(hayaminn == '[');
	if (scanf("%d", &kugyu->ayaneru) != 1) exit(1);
	hayaminn = getchar(); assert(hayaminn == ']');
	hayaminn = getchar(); assert(hayaminn == '(');
	hayaminn = getchar();
	if (hayaminn == '(') {
		ungetc('(', stdin);
		kugyu->tamurayukari = kitaeri();
		hayaminn = getchar(); assert(hayaminn == ')');
	} else {
		assert(hayaminn == ')');
		kugyu->tamurayukari = NULL;
	}
	return kugyu;
}

asumisu* miyukiti(const asumisu* sumipe, const asumisu* ayappe) {
	if (sumipe == NULL || ayappe == NULL) {
		return NULL;
	} else {
		asumisu* yukati = malloc(sizeof(asumisu));
		if (yukati == NULL) exit(1);
		yukati->ayaneru = sumipe->ayaneru + ayappe->ayaneru;
		yukati->hanazawakana = miyukiti(sumipe->hanazawakana, ayappe->hanazawakana);
		yukati->tamurayukari = miyukiti(sumipe->tamurayukari, ayappe->tamurayukari);
		return yukati;
	}
}

void mizuhasu(const asumisu* mimorin) {
	if (mimorin != NULL) {
		putchar('(');
		mizuhasu(mimorin->hanazawakana);
		printf(")[%d](", mimorin->ayaneru);
		mizuhasu(mimorin->tamurayukari);
		putchar(')');
	}
}

void yukinnko(asumisu* ayati) {
	if (ayati != NULL) {
		yukinnko(ayati->hanazawakana);
		yukinnko(ayati->tamurayukari);
		free(ayati);
	}
}

int main(void) {
	asumisu *nakamurayuuiti, *sakagutidaisuke, *riesyonn;
	nakamurayuuiti = kitaeri();
	sakagutidaisuke = kitaeri();
	riesyonn = miyukiti(nakamurayuuiti, sakagutidaisuke);
	mizuhasu(riesyonn); putchar('\n');
	yukinnko(nakamurayuuiti);
	yukinnko(sakagutidaisuke);
	yukinnko(riesyonn); /* itigomamire dayo~ */
	return 0;
}

Measured memory_bytes: 624
x = input().split(" ")
a = input().split(" ")
n = int(x[0])
m = int(x[1])
sum = 0
counter = 0
for i in a:
  sum += int(i)

bunsu = sum / 4 / m
 
for i in a:
    if float(i) >= bunsu:
      if counter <= m:
        counter += 1
if counter >= m:
  print("Yes")
else:
  print("No")
  




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

public class Main {

	static String[] character = {"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		for(int k = 0; k < n; k++){
			String str = br.readLine();
			
			if(str == null){
				break;
			}
			
			int prevI = 0;
			int prevJ = -1;
			for(int i = 0; i < str.length() ; i++){
				char c = str.charAt(i);
				
				if(c >= '1' && c <= '9'){
					prevI = c - '0';
					prevJ++;
					prevJ %= character[prevI].length();
				}
				else if(prevI != 0){
					System.out.print(character[prevI].charAt(prevJ));
					prevI = 0;
					prevJ = -1;
				}
			}
			System.out.println();
		}
		
	}

}

Measured memory_bytes: 25556
#include<cstdio>
#include<cmath>
#include <algorithm>

using namespace std;

int cost[500][500];
bool valid[500][500];
int N;

const int INF_COST = 500;

int get(int x,int y){
  if(x >= N || x < 0 || y >=N || y < 0)
    return INF_COST;
  else
    return cost[x][y];
}
//calculate cost
int cc(int min,int x,int y){
  if(x >= N || x < 0 || y >=N || y < 0)
    return INF_COST;
  int c = valid[x][y]?(cost[x][y]+1):(cost[x][y]);
  if(min > c){
    return c;
  }else{
    return INF_COST;
  }
}

void update(int x,int y){
  
  if(x >= N || x < 0 || y >=N || y < 0)
    return;
  int min = cost[x][y];
  bool updated = false;
  int cos=INF_COST;
  if((cos=cc(min,x+1,y  )) != INF_COST){
    min=cos;
    updated =true;
  }else if((cos=cc(min,x  ,y+1)) != INF_COST){
    min=cos;
    updated =true;
  }else if((cos=cc(min,x-1,y  )) != INF_COST){
    min=cos;
    updated =true;
  }else if((cos=cc(min,x ,y-1)) != INF_COST){
    min=cos;
    updated =true;
  }
  cost[x][y] = min;
  if(updated){
    //printf("update %d %d\n", x, y);
    update(x+1,y  );
    update(x  ,y+1);
    update(x-1,y );
    update(x  ,y-1);
  }

}

int main(){
  scanf("%d",&N);
  //init
  for(int x=0;x<N;++x){
      for(int y=0;y<N;++y){
        cost[x][y]= min(min(x,N-1-x),min(y,N-1-y));
        valid[x][y] = true;
      }
  }
  int count = 0;
  for(int i=0;i<N*N;++i){

    int id;
    scanf("%d",&id);
    int x = (id-1)%N;
    int y = (id-1)/N;
    
    count += cost[x][y];

    valid[x][y] = false;

    //printf("%d: %d\n",i,id);
    
    // for(int x=0;x<N;++x){
    //   for(int y=0;y<N;++y){
    //     printf("%d ,",cost[x][y]);
    //   }
    //   printf("\n");
    // }

    update(x+1,y  );
    update(x  ,y+1);
    update(x-1,y );
    update(x  ,y-1);

    //printf("%d: %d\n",i,id);
    
    // for(int x=0;x<N;++x){
    //   for(int y=0;y<N;++y){
    //     printf("%d ,",cost[x][y]);
    //   }
    //   printf("\n");
    // }
    
    //printf("\n");
  }
  printf("%d",count);
}


Measured memory_bytes: 23648
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) {
  if (A.size() == n+1) {
    int now = 0;
    rep(i,q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }

  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>

using namespace std;

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

	if(Y%1000 != 0) cout << "-1 -1 -1";
    
  	bool breakF = false;
  	for(int i=0; i<=N; i++){
     	for(int j=0; j+i<=N; j++){
          	int hideo_num = N - i - j;
          
          	int total = i*10000 + j*5000 + hideo_num*1000;
          
         	 if(Y == total){
               	cout << i << " " << j << " " << hideo_num << endl;
               	breakF = true;
              	break;
             }
        }
      	if(breakF) break;
    }
  	if(!breakF){
      	cout << "-1 -1 -1";
    }
}

Measured memory_bytes: 384
#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;
vector<int> a;
vector<int> charge; // charge[N] := NからN+1に行くのにかかる金額
int sum = 0;
/**********************************************/

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

    cin >> n;
    a.assign(n+2, 0);
    charge.assign(n+2, 0);
    FOR(i, 1, n+1) cin >> a[i];

    REP(i, n+1){
        charge[i] = abs(a[i] - a[i+1]);
        sum += charge[i];
    }
    FOR(i, 0, n){
        cout << sum - charge[i] - charge[i+1] + abs(a[i] - a[i+2]) << endl;
    }

}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<ll> &v) {
    std::for_each(v.begin(), v.end(), [](ll x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    //超えないと行けない時にめんどくさい
    int cnt = 0;
    int F = max(C, D);
    for(size_t i = A - 1; i < F; i++) {
        if(S[i] == '#') {
            cnt++;
        } else {
            cnt = 0;
        }
        if(cnt >= 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    if(B >= C) {
        cout << "Yes" << endl;
        return 0;
    }

    if(C <= D) {
        cout << "Yes" << endl;
        return 0;
    }
    // AからCへ
    // BからDへ
    if(D <= C) {
        for(int i = B - 1; i < D; i++) {
            if(S[i - 1] == '.' and S[i] == '.' and S[i + 1] == '.') {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
x = int(input())

if x == 2:
    print(x)
    exit()

ans = x
if ans%2 == 0:
    ans += 1
while True:
    i = 3
    while i < x:
        if ans%i == 0:
            break
        i += 2
    else:
        print(ans)
        exit()
    ans += 2
    


Measured memory_bytes: 2940
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

long long rev(long long p, long long x1, long long y1, long long x2, long long y2)
{
	if (!p) return 0;
	if (x1 / p != x2 / p && y1 / p != y2 / p) return 0;
	if (x1 / p == x2 / p && y1 / p == y2 / p) return rev(p / 3, x1 % p, y1 % p, x2 % p, y2 % p);
	if (x1 / p != x2 / p) return rev(p, y1, x1, y2, x2);
	if (x1 / p == 1 && x2 / p == 1){
		x1 %= p;
		x2 %= p;
		if (x1 > x2) swap(x1, x2);
		return min(x1 + 1, p - x2);
	}
	if (y1 > y2) swap(y1, y2);
	if (y2 / p - y1 / p == 2) return rev(p / 3, x1 % p, 0, x2 % p, p - 1);
	return max(rev(p / 3, x1 % p, 0, x2 % p, y2 % p), rev(p / 3, x1 % p, y1 % p, x2 % p, p - 1));
}

int main()
{
	int Q; scanf ("%d", &Q); while (Q--){
		long long x1, y1, x2, y2, base;
		scanf ("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
		base = abs(x1 - x2) + abs(y1 - y2);

		long long p = 1;
		for (int k = 0; k < 32; k++) p *= 3;
		base += 2 * rev(p, x1 - 1, y1 - 1, x2 - 1, y2 - 1);

		printf ("%lld\n", base);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int N; cin>>N;
  int n;
  n = N / 100;
  if(N <= n * 100 + n * 10 + n)cout<<n * 100 + n * 10 + n;
  else cout<<(n + 1) * 100 + (n + 1) * 10 + n + 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    int dp[n][n][k + 1] = {};
    for (int i = n - 1; i >= 0; i--) {
        for (int j = i; j <= n - 1; j++) {
            for (int l = 0; l <= k; l++) {
                if (i == j) {
                    dp[i][j][l] = 1;
                } else if (i + 1 == j) {
                    dp[i][j][l] = 2;
                    if (l == 0 && s[i] != s[j]) {
                        dp[i][j][l] = 1;
                    }
                } else {
                    dp[i][j][l] = max(dp[i + 1][j][l], dp[i][j - 1][l]);
                    // dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l] + 1);
                    if (s[i] == s[j]) {
                        dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l] + 2);
                    }
                    if (l != 0) {
                        dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l - 1] + 2);
                    }
                }
            }
        }
    }
    cout << dp[0][n - 1][k] << '\n';
    return 0;
}


Measured memory_bytes: 106112
#include <iostream>

#include <algorithm>
#include <functional>

using std::cin;
using std::cout;
using std::endl;

using std::greater;
using std::sort;

int
main()
{
  int N, K;
  cin >> N >> K;
  int A[200000] = {0};
  for (int n = 0; n < N; n++)
  {
    int i;
    cin >> i;
    A[i]++;
  }
  sort(&A[0], &A[200000], greater<int>());
  int count = 0;
  for (int k = K; k < 200000 && A[k] != 0; k++)
  {
    count += A[k];
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <utility>
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1e9
typedef long long int ll;
using namespace std;

int main()
{
    string s;
    cin >>s;

    if(s[0]=='Y' and s[1]=='A' and s[2]=='K' and s[3]=='I'){
        cout << "Yes" <<endl;
    }else{
        cout << "No"<< endl;
    }

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict


def main():
    N, P = list(map(int, input().split()))
    S = input()
    if P in [2, 5]:
        ans = 0
        # P = 2, 5の時は一番下の位の数だけ見ればカウント可能
        for right in range(N - 1, - 1, - 1):
            if int(S[right]) % P == 0:
                ans += right + 1
        print(ans)
        return
    # 例：S = 3543, P = 3
    # 左からn番目 ～ 1番右の数のmod Pの値を計算
    #     C = [3543, 543, 43, 3] % P = [0, 0, 1, 0]
    # C[m] == C[n] なる m < nのペア数 + C[n] == 0なるnの個数を求める
    #     3 + 3 = 6
    cur_c = 0
    C = [0] * N
    pw = 1
    for n, s in enumerate(S[::-1]):
        cur_c = (cur_c + pw * int(s)) % P
        C[N - 1 - n] = cur_c
        pw = (pw * 10) % P
    counter = defaultdict(int)
    for c in C:
        counter[c] += 1
    ans = 0
    for c in C:
        counter[c] -= 1
        ans += counter[c]
    ans += len([c for c in C if c == 0])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 17564
/+ dub.sdl:
	name "hello"
+/
import std.array;
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;

void main()
{
    auto N = readln.chomp.to!int;
    auto K = readln.chomp.to!int;
    auto x = readln.chomp.split(' ').map!(to!int).array;

    x.map!(n => min(n * 2, (K - n) * 2)).sum.writeln();
}


Measured memory_bytes: 256
def bubbleSort(a,n):
  flag = 1
  count = 0
  while flag:
    flag = 0
    for j in range(n-1,0,-1):
      if a[j] < a[j-1]:
        count += 1
        w = a[j]
        a[j] = a[j-1]
        a[j-1] = w
        flag = 1
  print(' '.join(map(str, a)))
  print(count)

n = int(input())
a = list(map(int, input().split()))
bubbleSort(a,n)


Measured memory_bytes: 5600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func isPalindrome(s string) bool {
	head := 0
	tail := len(s) - 1
	for head < tail {
		if s[head] != s[tail] {
			return false
		}
		head++
		tail--
	}
	return true
}

func main() {
	s := scanString()
	ans := "Yes"
	if !isPalindrome(s) {
		ans = "No"
	}

	l := len(s)
	if !isPalindrome(s[0 : (l-1)/2]) {
		ans = "No"
	}

	if !isPalindrome(s[(l+3)/2-1 : l]) {
		ans = "No"
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> originalList = new ArrayList();
		for(int i = 0; i < n; i++) {
			int number = sc.nextInt();
			originalList.add(number);
		}
		ArrayList<Integer> sortedList = (ArrayList<Integer>) originalList.clone();
		Collections.sort(sortedList);
		int maxNumber = sortedList.get(n - 1);
		int secondNumber = sortedList.get(n - 2);
		
		for(int i = 0; i < n; i++) {
			int t = originalList.get(i);
			if(originalList.get(i).equals(maxNumber)) {
				System.out.println(secondNumber);
			}else {
				System.out.println(maxNumber);
			}

		}
		

		
		

		
		
	}	

}



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

int main() {
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	vector<int> ans(n);
	ans[0]=0;
	ans[1]=abs(arr[1]-arr[0]);
	int pi;
	for(int i=2;i<n;i++)
	{
	    ans[i]=min(ans[i - 1] + abs(arr[i] - arr[i - 1]),ans[i - 2] + abs(arr[i] - arr[i - 2]));
	}
	cout<<ans[n-1]<<endl;
}

Measured memory_bytes: 1024
import sys
input=sys.stdin.readline

def main():
    h,w=map(int,input().split())
    S=[['#']*(w+1)]
    for _ in range(h):
        S.append(['#']+list(input().strip()))
    A=[[0]*(w+1) for _ in range(h+1)]
    for i in range(w+1):
        A[0][i]=float('inf')
    for i in range(h+1):
        A[i][0]=float('inf')
    A[1][1]=int(S[1][1]=='#')
    for i in range(1,h+1):
        for j in range(1,w+1):
            if i==1 and j==1:
                continue
            if S[i][j]=='.':
                A[i][j]=min(A[i-1][j],A[i][j-1])
            else: #S[i][j]=='#'
                A[i][j]=min(A[i-1][j]+int(S[i-1][j]=='.'),A[i][j-1]+int(S[i][j-1]=='.'))
    print(A[-1][-1])
    
if __name__=='__main__':
    main()

Measured memory_bytes: 41968
#include <stdio.h>
#include <stdlib.h>

#define N 100000
#define INF 1000000

typedef struct
{
    int go, back, cost;
} Date;

int n, d[N];
Date a[500000];
void root(int);

int main()
{
    int i, j, k, u, count = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d%d", &u, &k);
        for (j = 0; j < k; j++)
        {
            a[count].back = u;
            scanf("%d%d", &a[count].go, &a[count].cost);
            count++;
        }
    }
    root(count);
    for (i = 0; i < n; i++)
        printf("%d %d\n", i, d[i]);
    return 0;
}

void root(int b)
{
    int i, flag = 1;

    for (i = 0; i < n; i++)
        d[i] = INF;
    d[0] = 0;

    while (flag != 0)
    {
        flag = 0;
        for (i = 0; i < b; i++)
        {
            if (a[i].cost + d[a[i].back] < d[a[i].go])
            {
                d[a[i].go] = a[i].cost + d[a[i].back];
                flag = 1;
            }
        }
    }
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define MOD          1000000007 //10^9 + 7
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))

/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos))))
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end()); //will have index if A.begin() is minus from it
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1-1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
set <char> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
string S, T, U;

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

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

    // while(cin>>n){}
    cin>>S;
    //ll A[n];

    f0(i,S.sz)
    {
        A.insert(S[i]);
    }

    cout<<((S.sz==A.sz)?"yes":"no")<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define vvl vector<vector<ll>>
#define in(a) insert(a)
//#define rep(i,n) for(i=0;i<n;i++)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 

 ll n,m,s=0; cin>>n>>m;
 if(n==1||m==1)cout<<1;
 else{
 if(n%2==0){s=n/2;
 cout<<s*m;}
 else{
s=ceil(double(m)/2);
ll sum=0;
sum=s*ceil(double(n)/2);
s=m-s;
sum+=s*(n/2);
cout<<sum;
 }
}
return 0;


}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int k, q; cin >> k >> q;
  vll d(k);
  for(int i=0;i<k;++i) {
    cin >> d[i];
  }

  while(q) {
    q--;
    ll n, x, m; cin >> n >> x >> m;
    vll su1(k+1);
    for(int i=0;i<k;++i) {
      su1[i+1] = su1[i] + d[i] % m;
    }

    vll su2(k+1);
    for(int i=0;i<k;++i) {
      su2[i+1] = su2[i] + (d[i]%m == 0);
    }

    //printv(su1);
    //printv(su2);

    ll su = (n-1)/k * su1[k] + x%m + su1[(n-1)%k];
    ll su0 = (n-1)/k * su2[k] + su2[(n-1)%k];
    //cout << su << ":" << su0 << endl;

    ll ans = n-1;
    ans -= su / m;
    ans -= su0;
    cout << ans << endl;
  }

}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const int MX = 510000;
const int MAXN = 510000;

int n, q;
set<pair<int, int> > ss0;
set<pair<int, int> > ss1;
set<pair<int, int> > ss2;
int a[MAXN];
int b[MAXN];
ll c[MAXN];
vector<pair<int, int> > go[MX];
int p[MAXN];
int sz[MAXN];

int get(int a) {
	if (a == p[a])
		return a;
	return p[a] = get(p[a]);
}

int un(int a, int b) {
	a = get(a);
	b = get(b);
	if (a == b)
		return 0;
	if (sz[a] < sz[b])
		swap(a, b);
	sz[a] += sz[b];
	p[b] = a;
	return 1;
}

int main() {
	scanf("%d%d", &n, &q);
	ll mn = 1e9;
	for (int i = 0; i < q; ++i) {
		scanf("%d%d%lld", a + i, b + i, c + i);
		mn = min(mn, c[i]);
	}
	ll ans = mn * (n - 1);
	for (int i = 0; i < q; ++i)
		c[i] -= mn;
	for (int i = 0; i < q; ++i) {
		if (c[i] < MX)
			go[c[i]].push_back(make_pair(a[i], b[i]));
		if (c[i] + 1 < MX) {
			go[c[i] + 1].push_back(make_pair((a[i] + 1) % n, b[i]));
		}
	}
	for (int i = 0; i < n; ++i)
		p[i] = i, sz[i] = 1;
	for (int i = 0; i < MX; ++i) {
		for (auto j: go[i])
			ss0.insert(j);
		ss2.clear();
		for (auto j: ss0) {
			if (un(j.first, j.second))
				ss2.insert(make_pair((j.first + 1) % n, (j.second + 1) % n)), ans += i;
		}
		swap(ss0, ss2);
		swap(ss1, ss0);
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 46692
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????D???long D?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-3;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

D abs(D x, D y, D z){
    return sqrt(x*x + y*y + z*z);
}

D dot(D a1, D a2, D a3, D b1, D b2, D b3){
    return a1*b1 + a2*b2 + a3*b3;
}

D cross(D a1, D a2, D a3, D b1, D b2, D b3){
    D i = a2*b3 - a3*b2;
    D j = a3*b1 - a1*b3;
    D k = a1*b2 - a2*b1;
    return abs(i, j, k);
}

D distLP(D sx, D sy, D sz, D dx, D dy, D dz, D px, D py, D pz){
    return abs(cross(px-sx, py-sy, pz-sz, dx-sx, dy-sy, dz-sz))/abs(dx-sx, dy-sy, dz-sz);
}

D distSP(D sx, D sy, D sz, D dx, D dy, D dz, D px, D py, D pz){
    if(LE(dot(dx-sx, dy-sy, dz-sz, px-sx, py-sy, pz-sz), 0))
        return abs(px-sx, py-sy, pz-sz);
    if(LE(dot(sx-dx, sy-dy, sz-dz, px-dx, py-dy, pz-dz), 0))
        return abs(px-dx, py-dy, pz-dz);
    return distLP(sx, sy, sz, dx, dy, dz, px, py, pz);
}

class Circle{
public:
    D x, y, z, r;
    ll l;
    
    Circle(D x, D y, D z, D r, ll l): x(x), y(y), z(z), r(r), l(l){};
    
    bool intersect(D sx, D sy, D sz, D dx, D dy, D dz){
        return LE(distSP(sx, sy, sz, dx, dy, dz, x, y, z), r);
    }
};

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    
    int N, Q;
    cin >> N >> Q;
    vector<Circle> circles;
    for(int i=0; i<N; i++){
        D x, y, z, r;
        ll l;
        cin >> x >> y >> z >> r >> l;
        circles.push_back({x, y, z, r, l});
    }
    
    while(Q--){
        ll ans = 0;
        D sx, sy, sz, dx, dy, dz;
        cin >> sx >> sy >> sz >> dx >> dy >> dz;
        
        for(Circle &circle: circles){
            if(circle.intersect(sx, sy, sz, dx, dy, dz))
                ans += circle.l;
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long answer = Long.MIN_VALUE;

		answer = Math.max(answer, a * c);
		answer = Math.max(answer, b * c);
		answer = Math.max(answer, a * d);
		answer = Math.max(answer, b * d);

		System.out.println(answer);
 	}
}

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

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//



int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	
	string s;
	cin >> s;
	if(s == "ARC")
		cout << "ABC\n";
	else 
		cout << "ARC\n";
	
	
	
    return 0;
}




Measured memory_bytes: 3580
h,w,k = list(map(int, input().split()))
s = [input() for _ in range(h)]

strawberry = []

for i in s:
    if '#' in i:
        strawberry.append(True)
    else: strawberry.append(False)
ans = [[0]*w for _ in range(h)]

num = 0
for i in range(h):
    flag = 0
    if strawberry[i]:
        num += 1
        for j in range(w):
            if s[i][j]=='#':
                flag += 1
            if flag==2:
                num += 1
                flag = 1
            ans[i][j] = num

tmp = strawberry.index(True)
for i in range(h):
    if strawberry[i]==False:
        ans[i] = ans[tmp]
    else:
        tmp = i

for i in ans:
    print(' '.join(map(str,i)))


Measured memory_bytes: 7156
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back
#define endl '\n'
#define mp make_pair




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

	int k;
	cin>>k;
	string s;
	cin>>s;

	if(s.size()<=k)
	{
		cout<<s;
	}
	else{
		s=s.substr(0,k)+"...";
		cout<<s;
	}
	cout<<endl;
}



Measured memory_bytes: 3608
"use strict";

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

function main(input) {
  const [[numsCount], nums] = input.split("\n").map(s => s.split(" ").map(Number));

  let count = 0;

  let i = 0;
  while (i <= numsCount) {
    if (nums[i] === i + 1) {
      count++;
      if(nums[i + 1] === i + 2) {
        i++;
      }
    }
    i++;
  }

  const ans = count;
  console.log(ans);
}

Measured memory_bytes: 18764