akhauriyash/Code-Regression huggingface dataset:
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split())) for i in range(Q)]

dp = []

for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        dp.append(i)

def bs_left(l, target):
    low, high = 0, len(l)
    while low < high:
        mid = (low+high)//2
        if l[mid] < target:
            low = mid+1
        else:
            high = mid
    return low

def bs_right(l, target):
    low, high = 0, len(l)
    while low < high:
        mid = (low+high)//2
        if target < l[mid]:
            high = mid
        else:
            low = mid+1
    return low
for i in range(Q):
    il = bs_left(dp, lr[i][0]-1)
    ir = bs_right(dp, lr[i][1]-2)
    print(ir-il)

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

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

    int n,k;
    cin>>n>>k;

    vector<int> l(n);

    for(int i=0;i<n;i++)cin>>l[i];

    sort(l.begin(),l.end(),greater<int>());

    int ans=0;

    for(int i=0;i<k;i++)ans+=l[i];

    cout<<ans<<"\n";

    return 0;
}


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

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

    vector<int> numbmer(n, -1);

    bool failed = false;

    for (int i=0; i<m; i++) {
        int s,c;
        cin >> s >> c;

        if (numbmer.at(s-1) == -1 || numbmer.at(s-1) == c) {
            numbmer.at(s-1) = c;
        } else {
            failed = true;
        }
    }

    if (numbmer.at(0) == 0 && n != 1) failed = true;

    if (failed) {
        cout << -1 << endl;
    } else {
        if (n == 1) {
            if (numbmer.at(0) == -1) cout << 0 << endl;
            else cout << numbmer.at(0) << endl;
        } else {
            if (numbmer.at(0) == -1) {
                cout << 1;
                for (int i=0; i<n-1; i++) {
                    if (numbmer.at(i+1) == -1) cout << 0;
                    else cout << numbmer.at(i+1);
                }
                cout << endl;
            } else {
                for (int i=0; i<n; i++) {
                    if (numbmer.at(i) == -1) cout << 0;
                    else cout << numbmer.at(i);
                }
                cout << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 20
#define QN 200
int n,A[N];
int solve(int,int);

int main(){
  int i,q,m[QN];

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&m[i]);
  }
  for(i=0; i<q; i++){
    if(solve(0,m[i]) == 1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int solve(int i, int m){
  if(m == 0) return 1;
  if(i >= n) return 0;
  if(solve(i+1,m) == 1 || solve(i+1,m-A[i]) == 1) return 1;
}

Measured memory_bytes: 580
#include <iostream>
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <tuple>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

int f, dat[26][1050000];

void init(int n_, int x) {
    f = 1;
    while (f < n_) f *= 2;
    for (int i = 0; i < 2 * f - 1; i++) dat[x][i] = 0;
}

void add(int k, int x, int v) {
    k += f - 1;
    dat[x][k] += v;
    while (k > 0) {
        k = (k - 1) / 2;
        dat[x][k] = dat[x][k * 2 + 1] + dat[x][k * 2 + 2];
    }
}

int query(int a, int b, int k, int l, int r, int x) {
    if (r <= a || b <= l) return 0;
    
    if (a <= l && r <= b) return dat[x][k];
    else {
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2, x);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r, x);
        return vl + vr;
    }
}


int main() {
    int n;
    char s[500050];
    cin >> n >> s;

    for (int i = 0; i < 26; i++) init(n + 10, i);
    
    for (int i = 0; i < n; i++) {
        add(i + 1, s[i] - 'a', 1);
    }    

    int q;
    cin >> q;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int idx;  char c[1];
            cin >> idx >> c[0];
            //cerr << c[0] << s[idx - 1] << endl;
            if (c[0] != s[idx - 1]) {
                add(idx, s[idx - 1] - 'a', -1);
                add(idx, c[0] - 'a', 1);
            }
            s[idx - 1] = c[0];

        }
        else {
            int l, r, ans = 0;
            cin >> l >> r;
            for (int i = 0; i < 26; i++) {
                ans += (query(l, r + 1, 0, 0, f, i) > 0);
                //cout << query(l, r + 1, 0, 0, f, i);
            }
            //cout << " ";
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 107392
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
 
int main()
{
    string str1, str2;
    cin >> str1 >> str2;
 
    int pos1 = (int)str1.length() - 1, pos2 = (int)str2.length() - 1;
    while(pos1 >= 0)
    {
        if(str1[pos1] == str2[pos2] || str1[pos1] == '?')
        {
            int flag = 1;
            int i;
            for(i = 0; pos1 - i >= 0 && pos2 - i >= 0; i++)
            {
                if(str1[pos1 - i] != '?' && str1[pos1 - i] != str2[pos2 - i])
                {
                    flag = 0;
                    break;
                }
            }
            if(flag && i == (int)str2.length())
            {
                str1.replace(pos1-(int)str2.length()+1, str2.length(), str2);
                replace(str1.begin(), str1.end(), '?', 'a');
                cout << str1 << endl;
                return 0;
            }
        }
        pos1--;
    }
    cout << "UNRESTORABLE" << endl;
 
}

Measured memory_bytes: 256
import java.util.*;

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

		long[][] arr = new long[n+1][W+1];

		for(int i =0;i<=n;i++){
			for(int j=0;j<=W;j++){
				if(i==0||j==0) arr[i][j]=0;
				else if(j-weight[i-1]>=0) arr[i][j] = Math.max(arr[i-1][j],arr[i-1][j-weight[i-1]] + value[i-1]);
				else arr[i][j] =arr[i-1][j];
			}
		}
		System.out.println(arr[n][W]);
	}
}

Measured memory_bytes: 127444
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    ll N;
    cin >> N;
    vector<string> W(N);
    REP(i, N) cin >> W[i];
    unordered_map<string, int> S;
    REP(i, N){
        if (i < N-1){
            if(W[i].back() != W[i+1].front()){
                cout << "No" << endl;
                return 0;
            }

        }

        if (S[W[i]] == 0){
            S[W[i]] = 1;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a % 2 == 0 || b % 2 == 0) {
    cout << "Even" << endl;
  }
    else {
      cout << "Odd" << endl;
    }
  }

Measured memory_bytes: 3548
/*input
141421 356237
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

const ll MX = 1000005;

ll ifact[MX], fact[MX];

ll choose(ll n, ll r) {
	return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll n, m; cin >> n >> m;
	fact[0] = 1;
	for(ll i = 1; i < MX; i++) {
		fact[i] = (i * fact[i - 1]) % MOD;
	}
	for(ll i = 0; i < MX; i++) {
		ifact[i] = power(fact[i], MOD - 2, MOD);
	}
	ll run = 1, ans = 0;
	for(ll i = n; i >= 0; i--) {
		if(i & 1) {
			ans = (ans + MOD - choose(n, i) * run % MOD) % MOD;
		}
		else 
			ans = (ans + choose(n, i) * run % MOD) % MOD;
		if(i > 0)
			run = run * (m - (i - 1)) % MOD;
	}
	cout << run * ans % MOD;
	return 0;
}

Measured memory_bytes: 19272
using System;

public class Program
{
    public static long loop;

    static long n;

    static long[] a;

    static string output;

    public static void Main(string[] args)
    {
        loop = 0;

        Input();
        Proc();
        Output();
    }

    static void Input()
    {
        string[] input = null;

        // スペース区切りの整数の入力(横、個別)
        input = Console.ReadLine().Split(' ');

        n = long.Parse(input[0]);

        // スペース区切りの整数の入力(横、配列)
        input = Console.ReadLine().Split(' ');

        a = new long[n];
        for (long idx = 0; idx < n; idx++)
        {
            a[idx] = long.Parse(input[idx]);
        }
    }

    static void Proc()
    {
        long ans;
        long cost;

        long min_cost = GetCost(-100);

        for (ans = -99; ans <= 100; ans++)
        {
            cost = GetCost(ans);

            if (min_cost > cost)
            {
                min_cost = cost;
            }
        }

        output = min_cost.ToString();
    }

    static long GetCost(long ans)
    {
        long cost = 0;

        for (long idx = 0; idx < a.Length; idx++)
        {
            cost += (a[idx] - ans) * (a[idx] - ans);
        }

        return cost;
    }

    static void Output()
    {
        // 出力
        Console.WriteLine(output);
        output = string.Empty;
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<queue>
#include<cstddef>
#include<vector>
#include<string>
using ui = std::uint32_t;
using si = std::int32_t;

int main(){
	si h, w;
	std::cin >> h >> w;

	std::vector<std::vector<si>> board( h, std::vector<si>( w,0 ) );


	std::queue<std::pair<si, si>> que;
	que.emplace( -1, -1 );//sector


	for( si hi{}; hi < h; ++hi )
	{
		std::string t;
		std::cin >> t;
		for( si wi{}; wi < w; ++wi )
			if( t[wi] == '#' )
			{
				board[hi][wi] = 1;
				que.emplace( hi, wi );
			}
	}
	



	if( que.size() == w * h )
	{
		std::cout << 0 << "\n";
		return 0;
	}


	auto put = [&]()
	{
		for( const auto& e : board )
		{
			for( auto ee : e )
			{
				std::cout << ( ee == 0 ? '.' : '#' );
			}
			std::cout << "\n";
		}
		std::cout << "\n";
	};


	ui count{};
	while( !que.empty() )
	{
		const auto t = que.front(); que.pop();

		const auto th = t.first;
		const auto tw = t.second;
		if( tw == th && th == -1 )
		{
		//	put();
			if( !que.empty() )
			{
				++count;
				que.emplace( -1, -1 );
			}
			continue;
		}
		if( 0 < th && board[th - 1][tw] == 0 )
		{
			board[th - 1][tw] = 1;
			que.emplace( th-1, tw );
		}
		if( th + 1 < h && board[th + 1][tw] == 0 )
		{
			board[th + 1][tw] = 1;
			que.emplace( th+1, tw );
		}
		if( 0 < tw && board[th][tw - 1] == 0 )
		{
			++board[th][tw - 1];
			que.emplace( th, tw - 1 );
		}
		if( tw + 1 < w && board[th][tw + 1] == 0 )
		{
			++board[th][tw + 1];
			que.emplace( th, tw + 1 );
		}


	}

	std::cout << count -1 << "\n";

	return 0;
}

Measured memory_bytes: 12032
#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ULL unsigned long long
#define LL long long

using namespace std;

int main(){
	int N;
	
	cin >> N;
	
	int a,b,c;
	a=N%10;
	N-=a;N/=10;
	
	b=N%10;
	N-=b;
	
	c=N/10;
	
	
	if(a==7 || b==7 || c==7){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<string> vec(n);
  rep(i,n) cin >> vec[i];

  map<string,int> num;
  rep(i,n) num[vec[i]]++;

  //rep(i,n) cout << num[vec[i]] << endl;

  int max = 0;;
  for(auto p : num){
    auto k = p.first;
    auto v = p.second;
    if(max < v) max = v;
  }

  //cout << max << endl;

  for(auto p : num){
    auto k = p.first;
    auto v = p.second;
    if(v == max) cout << k << endl;
  }

  return 0;
}


Measured memory_bytes: 25144
//2018.09.20

#include <iostream>
using namespace std;

int main() {

    int n;
    cin >>n;

    int i;
    int ts[n],xs[n],ys[n];
    for(i=0;i<n;i++) cin >> ts[i] >> xs[i] >> ys[i];

    int t=0,x=0,y=0;
    int d;
    bool ans=true;
    for(i=0;i<n;i++){
        d=abs((xs[i]+ys[i])-(x+y));
        if(d>(ts[i]-t)){ ans = false; break;}
        else if((d-(ts[i]-t))%2!=0){ans = false; break;}
        else{
            x=xs[i]; y=ys[i]; t=ts[i];
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)



int main() {
	vector<bool> is_prime(100001, true);
	vector<int> d(100001, 0);
	is_prime[0] = false;
 	is_prime[1] = false;

	for (int i = 2; i * i <= 100000; i ++) {
		if (is_prime[i]) {
			for (int j = i + i; j <= 100000; j += i) {
				is_prime[j] = false;
			}
		}
	}

	vector <int> like_2017(100001, 0);

	for (int i = 1; i <= 100000; i+= 2) {
		if (is_prime[i] && is_prime[(i + 1) / 2]) {
			like_2017[i]++;
		}
	}

	vector<int> imos(100001, 0);
	for (int i = 1; i <= 100000; i+= 1) {
		imos[i] = imos[i -1] + like_2017[i];
	}

	int Q;
	cin >> Q;

	for (int i = 0; i < Q; i++) {
		int l,r;
		cin >> l >> r;
		cout << imos[r] - imos[l - 1] << endl;
	}
	
	return 0;
}

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


int main(){
  int x,n,t;
  cin >> n >> x >> t;
  cout << ((n-1)/x+1)*t << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define INF 1000000000000000001
#define ll long long
using namespace std;
using pll = pair<ll, ll>;


int main()
{
  ll K;
  cin >> K;
  queue<ll> q;
  for (ll i = 1; i < 10; ++i)
  {
    q.push(i);
  }
  ll cnt = 0;
  while (true)
  {
    ll check = q.front();
    cnt += 1;
    if (cnt == K)
    {
      cout << check << endl;
      return 0;
    }
    q.pop();
    ll botom = check % 10;
    if (botom == 0)
    {
      q.push(check * 10);
      q.push(check * 10 + 1);
    }
    else if (botom == 9)
    {
      q.push(check * 10 + 8);
      q.push(check * 10 + 9);
    }
    else
    {
      q.push(check * 10 + botom - 1);
      q.push(check * 10 + botom);
      q.push(check * 10 + botom + 1);
    }
  }
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> s(H); rep(i,H) cin >> s[i];
  vector<vector<int>> ans(H,vector<int>(W,0));
  int id=0;
  rep(y,H){
    int stcnt=0;
    rep(x,W){
      if(s[y][x]=='#')stcnt++;
    }
    if(stcnt!=0){
      id++;
      int scnt=0;
      rep(x,W){
        if(s[y][x]=='.'){
          ans[y][x] = id;
        }
        else{
          scnt++;
          if(scnt==1){
            ans[y][x] = id;
            scnt++;
          }
          else {
            scnt = 1;
            id++;
            ans[y][x] = id;
          }
        }
      }
    }
  }
  /*
  rep(y,H){
    rep(x,W){
      if(x!=0) cout << " " ;
      cout << ans[y][x];
    }
    cout << endl;
  }
  */
  rep(i,400)rep(y,H){
    if(ans[y][0] == 0 && y!=0){
      ans[y] = ans[y-1];
    }
  }
  rep(i,400)rep(y,H){
    if(ans[y][0] == 0 && y!=H-1){
      ans[y] = ans[y+1];
    }
  }
  if(ans[0][0] == 0){
    ans[0] = ans[1];
  }
  rep(y,H){
    rep(x,W){
      if(x!=0) cout << " " ;
      cout << ans[y][x];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	for(int t;cin>>t && t;){
		vector<double> es;
		for(int i=0;i<=t;i++){
			int n,m; cin>>n>>m;
			double e=0,psum=0;
			for(int j=0;j<m;j++){
				double v,p; cin>>v>>p;
				psum+=p;
				e+=v*p;
			}
			es.push_back(e/psum);
		}
		
		int i;
		for(i=0;i<t;i++)
			if(es[i]>es.back()+1e-7-1e-9)
				break;
		cout<<(i<t?"YES":"NO")<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
//?????´???????????????????°??????????(min)?????´????????¬??\????????¨??????????????????
//??????????????????min??????????°??????????(s0)??¨????????????min?????£?????????s0??§??????????????????????????????min??¨s0???????????????????????????????????????????????´??????????????????????????????????????????????????????
#include<stdio.h>
#include<limits.h>

void swap(int *a, int *b){
	int temp = *a;
	*a = *b;
	*b = temp;
	return;
}

void show(int A[], int n){
	int i;
	for( i = 0; i < n; i++ ){ printf("%5d", A[i]); }
	printf("\n");
	return;
}

void merge(int A[], int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1+1], R[n2+1];
	int i, j, k;
	for( i = 0; i < n1; i++ ){ L[i] = A[left+i]; }
	for( i = 0; i < n2; i++ ){ R[i] = A[mid+i]; }
	L[n1] = INT_MAX;
	R[n2] = INT_MAX;
	i = 0;
	j = 0;
	for( k = left; k < right; k++ ){
		if( L[i] <= R[j] ){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
		}
	}
	return;
}

void mergeSort(int A[], int left, int right){
	if( left+1 <  right ){
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
	return;
}

int minimumCostSort(int A[], int sorted[], int n){
	int i, j;
	int min, minj, target, targetj;
	int cost = 0, addCost, addCost2;	//???????????????????´????????????????min?????£?????????s0???????????´??????????????????
	for( i = 0; i < n; i++ ){
		min = sorted[i];
		//sorted???i?????????????´????A??????????????????(minj)????????????
		for( j = 0; j < n; j++ ){
			if( A[j] == min ){
				minj = j;
				break;
			}
		}
		addCost = 0;
		addCost2 = 2 * (A[minj] + sorted[0]);
		while( minj != i ){
			target = sorted[minj];
			for( j = 0; j < n; j++ ){
				if( A[j] == target ){
					targetj = j;
					break;
				}
			}
			addCost += A[minj] + A[targetj];
			addCost2 += sorted[0] + A[targetj];
			swap(&A[minj], &A[targetj]);
			minj = targetj;
			//show(A, n);
		}
		//?????????????????????????????????
		cost += (addCost<addCost2?addCost:addCost2);
	}
	return cost;
}

int main(){
	int n, i;
	int w[1000], sorted[1000];
	scanf("%d", &n);
	for( i = 0; i < n; i++ ){
		scanf("%d", &w[i]);
		sorted[i] = w[i];
	}
	mergeSort(sorted, 0, n);
	//show(w, n);
	//show(sorted, n);
	printf("%d\n", minimumCostSort(w, sorted, n));
	return 0;
}

Measured memory_bytes: 608
n = int(input())
SP = []
for i in range(n):
    s,p = input().split()
    sp = (i,s,int(p))
    SP.append(sp)

newSP = sorted(SP,key = lambda tup:(tup[1],-tup[2]))

for i in range(n):
    print(newSP[i][0] + 1)


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

using ll = long long;
using ull = unsigned long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define bzero(p, n) memset(p, 0, n)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}

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

    int N;
    cin >> N;
    
    vector<int> A(N);
    int a_max[2] = { INT_MIN, INT_MIN };
    rep(i, N) {
        cin >> A[i];
        if (A[i] >= a_max[0]) {
            a_max[1] = a_max[0];
            a_max[0] = A[i];
        } else if (A[i] > a_max[1]) {
            a_max[1] = A[i];
        }
        
    }

    rep(i, N) {
        cout << (A[i] == a_max[0] ? a_max[1] : a_max[0]) << endl; 
    }
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int h,n,a,sum=0;
  cin>>h>>n;
  while(n--){
    cin>>a;
    sum=sum+a;
  
  }
  if(sum>=h) cout<<"Yes";
  else 
    cout<<"No";
  
  
  
 return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main(){
	int N;
	cin >> N;
 
	vector<int> A, B;
	for (int i = 0; i < N; i++){
		int At, Bt;
		cin >> At >> Bt;
		A.push_back(At);
		B.push_back(Bt);
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
 
	if (N % 2){
		cout << B[N/2] - A[N/2] + 1 << endl;
	} else {
		cout << B[N / 2] + B[N / 2 - 1] - A[N / 2] - A[N / 2 - 1] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 5108
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleContexts #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO
import Data.Function
import Control.Monad.Primitive
import qualified Data.Vector.Primitive.Mutable as VPM
import qualified Data.Vector.Generic.Mutable as VGM
import Data.STRef


rInt :: StateT BSL.ByteString Maybe Int
rInt = StateT $ BSL.readInt . BSL.dropWhile (<'!')


main :: IO ()
main = do
  [n,capacity] <- map read . words <$> getLine
  wvs <- VU.unfoldrN n (runStateT $ (,) <$> rInt <*> rInt)
         <$> BSL.getContents
  print $ query n capacity wvs

query :: Int -> Int -> VU.Vector (Int, Int) -> Int
query n capacity = (VU.! capacity)
  . VU.foldl'
    (\vec (w,v) ->
       VU.zipWith max vec $ VU.replicate w 0 VU.++ VU.map (v+) vec)
    (VU.replicate (capacity+1) 0)


Measured memory_bytes: 6908
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*
ac
含まれない部分文字列の最後の文字をαに固定する．
すると，最後に出てきたαよりも前の文字列の中に含まれない最短部分文字列を求める問題に帰着された．
順番に気をつけよう（1敗）（右から左へのdpでないと辞書順にならない）
*/

int dp[200010]={},before[200010][26];
string a;

int f(int i){
	if(i>a.size())return 0;
	if(dp[i]!=0)return dp[i];
	int smallest=1e9;
	rep(j,26){
		smallest=min(smallest,f(before[i][j]+1));//最後がj種類目のアルファベットで終わる最短文字列
	}
	return dp[i]=smallest+1;
}

string g(int i){
	if(i>a.size())return "";
	rep(j,26){
		if(f(before[i][j]+1)+1==dp[i])return (char)('a'+j)+g(before[i][j]+1);
	}
	return "ああああああ！！！！！！！！！";
}

int main(void){
	cin>>a;
	rep(j,26)before[a.size()][j]=a.size();//まだ出てない文字
	dp[a.size()]=1;//空文字列に含まれない最短部分列の長さは1（1敗）
	irep(i,a.size()){
		rep(j,26)before[i][j]=before[i+1][j];
		before[i][a[i]-'a']=i;
	}
	f(0);
	cout<<g(0)<<endl;
	return 0;
}

Measured memory_bytes: 22276
//by Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<s32>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cout << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

int main()
{
	FASTIO;
	string s,t;
	cin >> s >> t;
	int n_s = s.length(),n_t = t.length();
	vector<s32> cnt(26,s32());
	for(int i = 0;i < n_s;i++) cnt[s[i] - 'a'].insert(i);
	ll ans = 0;
	int prev = -1;
	for(int i = 0;i < n_t;i++){
		int z = t[i] - 'a';
		auto itr = cnt[z].lower_bound(prev + 1);
		if(itr == cnt[z].end()){
			ans += (n_s - prev - 1);
			itr = cnt[z].lower_bound(0);
			if(itr == cnt[z].end()){
				cout << "-1" << ln;
				return 0;
			}
			prev = *itr;
			//cout << *itr << ln;
			ans += (prev + 1);
		}
		else{
			int temp = prev;
			prev = *itr;
			//cout << *itr << ln;
			ans += (prev - temp);
		}
	}
	cout << ans << ln;
	return 0;
}


Measured memory_bytes: 5200
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 353;
ll i,n,a,mx,s;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,0,n){
        cin>>a;
        s += a;
        mx = max(mx,a);
    }
    cout<<s - mx / 2;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  
  int cnt=0;
  for (int i=0;i<n;++i){
    cin >> a[i];
    if (a[i]%2==1) cnt++;
  }
  
   if (cnt==n) cout << pow(3,n)-1 << endl;
   else cout << pow(3,n)-pow(2,n-cnt) << endl;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  int64_t sum=0;
  for(int i=0;i<N;i++)
    sum+=A.at(i);
  vector<int64_t>B(N-1);
  int64_t x=0;
  for(int i=0;i<N-1;i++){
  x+=A.at(i);
  B.at(i)=abs(sum-2*x);
  }sort(B.begin(),B.end());
  cout<<B.at(0)<<endl;
   return 0;
}

Measured memory_bytes: 3328
#include <cstdio>

using namespace std;

int main()
{
    char s[30];
    int n, point, runner, out;
    scanf( "%d\n", &n );
    for( int i = 0; i < n; i++ )
    {
        point = 0, runner = 0, out = 0;
        while( out < 3 )
        {
            scanf( "%s\n", s );

            switch( s[1] )
            {
                case 'I':
                    runner++;
                    if( runner == 4 )
                    {
                        point++;
                        runner = 3;
                    }
                    break;
                case 'O':
                    point += runner + 1;
                    runner = 0;
                    break;
                case 'U':
                    out++;
                    break;
            }
        }
        printf( "%d\n", point );
    }
    return 0;
}



Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,r,l) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define INF (1LL<<62)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
const double PI = atan(1)*4;
const int MAXN = 1e5+20;
const double EPS = 1e-9;
ll dp[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<< setprecision(2)<< fixed;
    int n;
    cin>>n;
    ll h[n];
    forn(i,n){
        cin>>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    fore(i,2,n-1){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll A[n];
    ll cnt=0,ans=0;
    for(int i=0;i<n;i++)cin>>A[i];
    for(int i=n-1;i>=1;i--){
        if(A[i]<=A[i-1])cnt++;
        else{
            ans=max(ans,cnt);
            cnt=0;
        }
        //cout<<cnt<<" ";
    }
    ans=max(ans,cnt);
    cout<<ans;
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int count = 0;
    for (int i = 1; i <= n; i++) {
        int num = 0;
        num = i / 10000;
        num += (i - (i / 10000) * 10000) / 1000;
        num += (i - (i / 1000) * 1000) / 100;
        num += (i - (i / 100) * 100) / 10;
        num += (i - (i / 10) * 10);
        if (num >= a && num <= b) {
            count += i;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            string[] imp = Console.ReadLine().Split(' ');
            int n, m;
            n = int.Parse(imp[0]);
            m = int.Parse(imp[1]);
            char[][] a = new char[n][];
            char[][] b = new char[m][];
            for (int i = 0; i < n; i++)
                a[i] = Console.ReadLine().ToCharArray();
            for (int i = 0; i < m; i++)
                b[i] = Console.ReadLine().ToCharArray();
            bool f = true;
            for (int p = 0; p <= n - m; p++)
            {
                for (int q = 0; q <= n - m; q++)
                {
                    f = true;
                    for (int i = 0; i < m; i++)
                        for (int j = 0; j < m; j++)
                            f = f && a[p + i][q + j] == b[i][j];
                    if (f)
                        break;
                }
                if (f)
                    break;
            }
            if (f)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            
        }

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11348
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

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

	public static void main(String[] args) {

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

		try {
			int M = Integer.parseInt(br.readLine());
			int in_num[] = new int[M];
			int table[][] = new int[M][M]; //自分より遅い人を格納するテーブル
			int index[] = new int[M];


			for(int i = 0; i < M; i++){
				in_num[i] = 0;
				index[i] = 0;
			}

			int N = Integer.parseInt(br.readLine());
			String input_str[] = new String[2];


			int first,second;

			for(int loop = 0; loop < N; loop++){
				input_str = br.readLine().split("\\s+");
				first = Integer.parseInt(input_str[0]);
				second = Integer.parseInt(input_str[1]);
				first--;
				second--;
				in_num[second]++;
				table[first][index[first]++] = second;
			}

			Queue<Integer> Q = new ArrayDeque<Integer>();

			for(int i = 0; i < M; i++){
				if(in_num[i] == 0){
					Q.add(i);
				}
			}

			int tmp;
			StringBuilder ans = new StringBuilder();

			while(!Q.isEmpty()){
				tmp = Q.peek();
				Q.poll();

				ans.append(Integer.toString(tmp+1)).append("\n");

				for(int i = 0; i < index[tmp]; i++){
					in_num[table[tmp][i]]--;
					if(in_num[table[tmp][i]] == 0){
						Q.add(table[tmp][i]);
					}
				}
			}

			System.out.print(ans.toString());


		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}




Measured memory_bytes: 24716
using System;
class ITP1_9_B
{
    static void Main()
    {
        while (true)
        {
            string card = Console.ReadLine();
            if (card == "-") break;
            int m = int.Parse(Console.ReadLine());
            for (int i = 0; i < m; i++)
            {
                int pos = int.Parse(Console.ReadLine());
                card = card.Substring(pos) + card.Substring(0,pos);
            }
            Console.WriteLine(card);
        }
    }
}

Measured memory_bytes: 5380
#include <iostream>
using namespace std;
int main(void){
    int r,c,sum,total_sum=0;
    
    cin>>r>>c;
    
    int table[r+1][c+1];
    
    for(int i=0; i<r+1; i++){
        for(int j=0; j<c+1; j++){
            table[i][j]=0;
        }
    }
    
    for(int i=0; i<r; i++){
        sum=0;
        for(int j=0; j<c; j++){
            cin>>table[i][j];
            sum+=table[i][j];
            table[r][j]+=table[i][j];
        }
        table[i][c]=sum;
        total_sum+=sum;
    }
    table[r][c]=total_sum;
    
    for(int i=0; i<r+1; i++){
        for(int j=0; j<c; j++){
            cout<<table[i][j]<<" ";
        }
    cout<<table[i][c]<<endl;
    }
}



Measured memory_bytes: 3080
n = gets.to_i
k = gets.to_i
x = gets.split(" ").map!{|i| i.to_i}
min = 0
n.times do |j|
 a = 2*x[j]
 b = 2*(k - x[j]).abs
 if a >= b
   min += b
 else min += a
 end
end
puts min


Measured memory_bytes: 1788
from itertools import combinations
n = int(input())
state = [None] + [[set(),set()] for _ in range(n)]

for i in range(1,n+1):
    a = int(input())
    for _ in range(a):
        x,y = map(int,input().split())
        if y == 0:
            state[i][0].add(x)
        if y == 1:
            state[i][1].add(x)

ans = 0
#正直者の人数を仮定
for i in range(1,n+1):
    #正直者の選び方を仮定
    for j in combinations(list(range(1,n+1)), i):
        assum = set(j)
        state_lst = []
        #正直者の証言抽出
        for each_state in j:
            state_lst.append(state[each_state])
        #証言の矛盾を確認
        for each_state in state_lst:
            crr0 = assum.isdisjoint(each_state[0])
            crr1 = assum >= each_state[1]
            crr = crr0 and crr1
            if not crr:
                break
        else:
            ans = i

print(ans)

Measured memory_bytes: 74236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


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

    int cnt = 0;
    rep(i, S.size()) {
        if (S[i] == 'o') ++cnt;
        if (cnt + 15 - i-1 < 8) {
            NO;
            return 0;
        }
    }
    YES;
    return 0;
}



Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let K: usize = sc.get();
    let N = 50;
    let rem = K % N;
    println!("{}", N);
    let mut ans = Vec::new();
    for i in 0..N {
        if i < rem {
            ans.push(N-1 + N + (K/N) - (rem-1));
        } else {
            ans.push(N-1 + (K/N) - rem);
        }
    }
    for i in 0..N {
        if i != N-1 {
            print!("{} ", ans[i]);
        } else {
            print!("{}", ans[i]);
        }
    }
    println!("");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    int n, ans;
    cin >> n;
    vector<int> a(n), c;
    rep(i, n)cin >> a.at(i);
    ans = a.at(0);
    REP(i, n-1)ans = __gcd(ans, a.at(i));
    cout << ans;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
while(true){
int h,w;
cin>>h>>w;
if(h==0&&w==0)
return 0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if((i%2==0&&j%2==0)||(i%2==1&&j%2==1))
cout<<'#';
else
cout<<'.';

}
cout<<'\n';
}
cout<<'\n';

}





}

Measured memory_bytes: 3072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ABC158D
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int Q = int.Parse(Console.ReadLine());
            StringBuilder sb1 = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();

            bool reverse = false;
            for (int i = 0; i < Q; i++)
            {
                var input = Console.ReadLine().Split().ToArray();
                
                if (input[0] == "1")
                {
                    reverse = !reverse;
                    continue;
                }

                if (!reverse)
                {
                    if (input[1] == "2") sb1.Append(input[2]);
                    else if (input[1] == "1")sb2.Append(input[2]);
                }
                else
                {
                    if (input[1] == "1") sb1.Append(input[2]);
                    else if (input[1] == "2") sb2.Append(input[2]);
                }
            }
            S = new string(sb2.ToString().Reverse().ToArray()) + S + sb1;
            if (reverse) S = new string(S.Reverse().ToArray());

            Console.WriteLine(S);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 23344
#include"bits/stdc++.h"
using namespace std;
#define int int64_t
int ar[(int)1e5+10];
int br[(int)1e5+10];
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;cin>>a>>b;
    a+=b[b.length()-1];
    if(a==b)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3652
n,k=map(int,input().split())
s=input()
happy=0
seq=[]
cur=s[0]
seq.append(cur)
for i in range(1,n):
  if s[i]!=cur:
    seq.append(s[i])
    cur=s[i]
  else:
    happy=happy+1

if len(seq)%2==1:
  rev=len(seq)//2
  print(happy+min(rev,k)*2)
else:
  rev=len(seq)//2
  if rev>k:
    print(happy+k*2)
  else:
    print(happy+(rev-1)*2+1)


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int N;
  cin >> N;
  vector<ll> R, G, B;
  string s;
  cin >> s;
  rep(i,N){
    char a = s.at(i);
    if(a == 'R') R.push_back(i+1);
    if(a == 'G') G.push_back(i+1);
    if(a == 'B') B.push_back(i+1);
  }
  ll ans = R.size() * G.size() * B.size();
  for(ll i = 0; i < N; i++){
    for(ll j = i+1; 2*j - i < N && 2*j - i >= 0 && j < N; j++){
      if(!(s.at(i) == s.at(j) || s.at(2*j-i) == s.at(i)||s.at(j) == s.at(2*j - i))){
        ans--;
      }
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 3688
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
	int N;
	cin >> N;
	vector<int> P(N);
	rep(i, N) cin >> P[i];
	int counter = 0;
	string ans = "YES";
	rep(i,N) {
		if (P[i]!=(i+1)) {
			counter++;
			if (2<counter) {
				ans = "NO";
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n;
	int a[110];
	int t;
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=n-1;i>=0;i--){
		printf("%d",a[i]);
		if(i!=0) printf(" ");
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 2108