akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<deque>
using namespace std;

int main(){
	int N, L;
	cin >> N >> L;
	vector<int> a(N);
	for(int i = 0; i < N; i++) cin >> a[i];
	deque<int> dqa;
	for(int i = 0; i < N; i++){
		while(!dqa.empty() && a[dqa.back()] >= a[i]) dqa.pop_back();
		dqa.push_back(i);
		if(i >= L - 1){
			cout << a[dqa.front()] << (i == N - 1 ? '\n' : ' ');
			if(dqa.front() == i - L + 1) dqa.pop_front();
		}
	}
	return 0;
}



Measured memory_bytes: 6764
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
///////////////////////////
//区間最大
struct RBQ{
    ll n;
    vector<ll>data;
    RBQ(ll vs){
        n=1;
        while(n<vs)n*=2;
        data.resize(2*n-1,-inf);
    }
    void update(ll k,ll a){
        k+=n-1;
        data[k]=a;
        while(k>0){
            k=(k-1)/2;
            data[k]=max(data[2*k+1],data[2*k+2]);
        }
    }
    ll query(ll a,ll b,ll k,ll l,ll r){
        if(r<=a||b<=l)return -inf;
        if(a<=l&&r<=b){
            return data[k];
        }else{
            ll vl=query(a,b,2*k+1,l,(l+r)/2);
            ll vr=query(a,b,2*k+2,(l+r)/2,r);
            return max(vl,vr);
        }
    }
    ll query(ll a,ll b){return query(a,b,0,0,n);}//[a,b)の最大値
};
//////////////////////////////////////////////////////


int main(){fastio
    ll n;cin>>n;
    l_l x[n];
    rep(i,0,n-1){
        cin>>x[i].fi>>x[i].se;
    }
    sort(x,x+n);
    RBQ nx(n+1);
    nx.update(n,n);
    rep(i,0,n-1){
        nx.update(i,lower_bound(x,x+n,l_l{x[i].fi+x[i].se,-inf})-x);
    }
    for(ll i=n-1;i>=0;i--){
        nx.update(i,nx.query(i,nx.query(i,nx.query(i,i+1))));
    }
    ll dp[n+1];memset(dp,0,sizeof(dp));
    dp[0]=1;
    rep(i,0,n-1){
        Add(dp[i+1],dp[i]);
        Add(dp[nx.query(i,i+1)],dp[i]);
    }
    //rep(i,0,n-1)cout<<nx.query(i,i+1)<<" ";cout<<endl;
    //rep(i,0,n)cout<<dp[i]<<" ";cout<<endl;
    cout<<mod(dp[n])<<endl;
    
    return 0;
}


Measured memory_bytes: 9088
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int N;
  while (scanf("%d", &N) != EOF) {
    vector<ll> v(N + 1);
    for (int i : range(N)) {
      int x;
      scanf("%d", &x);
      v[i] = (ll)x;
    }

    ll res = 0, tot = 0;
    for (int i : range(N + 1)) {
      if (v[i] > 0) {
        tot += v[i];
      } else {
        res += tot / 2;
        tot = 0;
      }
    }

    printf("%lld\n", res);
  }
}


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

int main() {
    string N;
    cin >> N;
    if (N[1]==N[2] && (N[0]==N[1] || N[2]==N[3])){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    h,w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    b = [list(map(int, input().split())) for _ in range(h)]
    c = [[0]*w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            c[i][j] = abs(a[i][j] -b[i][j])

    # 80*160//2 xbit目が1→数値x-6400を取る
    mid = 6400
    dp = [[0]*w for _ in range(h)]
    dp[0][0] = (1<<(mid+c[0][0])) | (1<<(mid-c[0][0]))
    for x in range(h):
        for y in range(w):
            for dx, dy in [[0, 1], [1, 0]]:
                nx = x + dx
                ny = y + dy
                if 0<=nx<h and 0<=ny<w:
                    dp[nx][ny] = dp[nx][ny] | (dp[x][y]<<c[nx][ny])
                    dp[nx][ny] = dp[nx][ny] | (dp[x][y]>>c[nx][ny])
    
    for i in range(mid+1):
        if (dp[-1][-1]>>i) & 1:
            res = mid - i
    print(res)

if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 58;

int main()
{
  int N, A[100000];
  char op[100000];

  cin >> N;
  for(int i = 0; i < N; i++) {
    if(i > 0) cin >> op[i];
    cin >> A[i];
  }

  int64 dp[3] = {A[0], -INF, -INF};
  for(int i = 1; i < N; i++) {
    if(op[i] == '+') {
      dp[0] = max(dp[0], dp[1]) + A[i];
      dp[1] -= A[i];
      dp[2] += A[i];
    } else {
      dp[2] = max(dp[1], dp[2]) + A[i];
      dp[1] = max(dp[0], dp[1]) - A[i];
      dp[0] -= A[i];
    }
  }
  cout << max({dp[0], dp[1], dp[2]}) << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
int main()
{
    int h,w;
    cin>>h>>w;
    string s[h];
    rep(i,h)cin>>s[i];
    const int dh[8]={1,1,1,0,0,-1,-1,-1};
    const int dw[8]={-1,0,1,-1,1,-1,0,1};
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#')continue;
            int sum=0;
            rep(k,8){
                int ni=i+dh[k];
                int nj=j+dw[k];
                if(ni<0||h<=ni)continue;
                else if(nj<0||w<=nj)continue;
                else if(s[ni][nj]=='#')sum++;
            }
            s[i][j]=char(sum+'0');
        }
    }
    rep(i,h)cout<<s[i]<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000000

int H,A[MAX+1],a,i;

void maxHeapfy(int i){
  int l,r,largest;
  l = 2*i;
  r = 2*i+1;

  if(l <= H && A[l]>A[i])largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest])largest=r;

  if(largest != i){
    a=A[i];
    A[i]=A[largest];
    A[largest]=a;
    maxHeapfy(largest);
  }
}

int main(){
  scanf("%d",&H);

  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  for(i=H/2;i>=1;i--){
    maxHeapfy(i);
  }
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

    
    



Measured memory_bytes: 3680
#include<iostream>
#include<string>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;
int n;
string s;
int main(){
	cin>>n>>s;
	int bcnt=0;
	int wcnt=0;
	vector<vector<int>> mem(2,vector<int> (n+1,0));//0しろ1黒
	for (int i = 0; i < n; i++)
	{
		if (s[i]=='#')
		{
			bcnt++;
		}else{
			wcnt++;
		}
		mem[0][i]=wcnt;
		mem[1][i]=bcnt;
	}
	int m=n-mem[1][n-1];
	for (int i = 1; i <= n; i++)
	{
		m=min(m,n-i+2*mem[1][i-1]-mem[1][n-1]);
	}
	cout<<m<<endl;
}


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

int main() {
    string sa, sb, sc;
    cin >> sa >> sb >> sc;

    char next = sa[0];
    int ia = 1, ib = 0, ic = 0;
    int na = sa.size() + 1, nb = sb.size() + 1, nc = sc.size() + 1;
    string ans;
    while (1) {
        if (next == 'a') { next = sa[ia]; ia++; }
        else if (next == 'b') { next = sb[ib]; ib++; }
        else { next = sc[ic]; ic++; }

        if (ia == na) { ans = 'A'; break; }
        else if (ib == nb) { ans = 'B'; break; }
        else if (ic == nc) { ans = 'C'; break; }
    }
    cout << ans << endl;
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] A = new int[2][N];

		for(int j=0; j<2; j++) {
			for(int i=0; i<N; i++) {
				A[j][i] = sc.nextInt();
			}
		}

		int[] sum = new int[N];
		for(int k=0; k<N; k++) {
			for(int l=0; l<=k; l++) {
				sum[k] += A[0][l];
			}for(int m=N-1; m>=k; m--) {
				sum[k] += A[1][m];
			}
		}Arrays.sort(sum);

		System.out.println(sum[N-1]);

	}

}


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

int main()
{
    char s[101];

    while(scanf("%s", s) != EOF)
    {
        int len = strlen(s);
        int frequency[26] = {0};
        for(int i=0; i<len; i++) frequency[s[i] - 'a']++;
        int beautiful = 0;
        for(int i=0; i<26; i++) beautiful |= frequency[i];
        if(beautiful & 1) cout << "No\n";
        else cout << "Yes\n";
    }
    return 0;
}



Measured memory_bytes: 256
using System;

namespace AtCoder
{
  public class Program
  {
    static void Main(string[] args)
    {
      string[] input = Console.ReadLine().Split(' ');
      int x = int.Parse(input[0]);
      int y = int.Parse(input[1]);
      int result = 0;
      int turu = x;
      int kame = 0;
      int num_turu = 0;
      int num_kame = 0;
      int cnt = 0;
      bool judge = false;

      if (y % 2 != 0 || y == 0)
      {
        Console.Write("No");
      }
      else
      {
        while (true)
        {
          num_turu = 0;
          num_kame = 0;
          if (turu < 0)
          {
            break;
          }
          else
          {
            for (int i=0; i<turu; i++)
            {
              num_turu = num_turu + 2;
            }
            for (int j=0; j<kame; j++)
            {
              num_kame = num_kame + 4;
            }
            result = num_turu + num_kame;
            if (result == y)
            {
              judge = true;
              break;
            }
            turu = turu - 1;
            kame = kame + 1;
          }
        }
        if (judge == true)
        {
          Console.Write("Yes");
        }
        else
        {
          Console.Write("No");
        }
      }
    }
  }
}


Measured memory_bytes: 27448
import sys

x, k, d = map(int,input().split())
x = abs(x)
ans = 0

if k <= x // d:
    ans = x - k*d
    print(ans)
    sys.exit()

if (k - (x // d)) % 2 == 0:
    print(x % d)
else:
    print(abs(x % d - d))

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N, A;
    cin >> N >> A;

    cout << (N + A - 1) / A << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int n;
    while (cin >> n, n) {
        vector<string> data(n);
        rep(i, n) {
            cin >> data[i];
            rep(j, data[i].size()) {
                if (!i) { break; }
                if (data[i][j] != '.') {
                    data[i][j-1] = '+';
                    break;
                }
            }
        }
        for (int i = n-1; i >= 0; i--) {
            rep(j, data[i].size()) {
                if (data[i][j] == '+') {
                    int pt = i-1;
                    while (pt >= 0 && data[pt][j] == '.') {
                        data[pt--][j] = '|';
                    }
                    break;
                }
            }
        }
        rep(i, n) {
            rep(j, data[i].size()) {
                if (data[i][j] == '.') {
                    data[i][j] = ' ';
                }
            }
            cout << data[i] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3660
N, M, K = map(int, input().split())
F = [[] for _ in range(N)]
B = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    F[a].append(b)
    F[b].append(a)

for _ in range(K):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    B[c].append(d)
    B[d].append(c)


class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根(最初は全て根)
        self.par = [i for i in range(n)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * n
        # 人間の数
        self.size = [1] * n

    # 検索
    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        # 根でないなら、親の要素で再検索
        else:
            # 走査していく過程で親を書き換える(return xが代入される)
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)


UF = UnionFind(N)
for iam in range(N):
    for friend in F[iam]: 
        UF.union(iam, friend) # 自分と自分の友達を併合

ans = [UF.size[UF.find(iam)] - 1 for iam in range(N)] # 同じ集合に属する人の数

for iam in range(N):
    ans[iam] -= len(F[iam]) # すでに友達関係にある人達を引く

for iam in range(N):
    for block in B[iam]:
        if UF.same(iam, block): # ブロック関係にあったら引く
            ans[iam] -= 1

print(*ans, sep=' ')


Measured memory_bytes: 48364
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


signed main(){
  string s;
  cin>>s;
  char ns='A';
  int ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]-ns<=0)ans++;
    ns=s[i];
  }
  cout<<ans<<endl;
  return 0;
}

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

typedef long long ll;

int main() {        
	int n;
	cin >> n;
	int v[2][n];
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> v[i][j];
		}
	}
	int left[n];
	left[n - 1] = v[1][n - 1];
	for (int i = n - 2; i >= 0; --i) {
		left[i] = v[1][i] + left[i + 1];
	}
	int maxm = 0;
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		sum += v[0][i];
		maxm = max(maxm, sum + left[i]);
	} 
	
	cout << maxm;
}






Measured memory_bytes: 3628
n,q=map(int,input().split())
s=input()
lis=[list(map(int,input().split())) for i in range(q)]
g=[0]*n
cnt=0
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    cnt+=1
    g[i+1]=cnt
  else:
    g[i+1]=cnt

for i in range(q):
  print(g[lis[i][1]-1]-g[lis[i][0]-1])

Measured memory_bytes: 30656
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Streamline | diff Streamline.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Streamline.cpp && ./a.out

/*
 
 2/10/2019
 
 18:12-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N,M;

LL solve() {
  if(N<=M) return 0;
  vector<LL> B(N-1);
  sort(A,A+N);
//  dumpC(A,A+N);
  REP(i,N-1) B[i]=A[i+1]-A[i];
  sort(ALL(B));
//  dumpc(B);
  LL res=accumulate(B.begin(),B.begin()+N-M,0LL);
//  res+=N-M;
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>M>>N;
  REP(i,N) cin>>A[i];
  cout<<solve()<<endl;
  
  return 0;
}


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

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

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

Measured memory_bytes: 3632
#include<bits/stdc++.h> 
#define ll long long int
#define ld long double
#define maxim (ll)1000000000000
#define PB push_back
#define MP make_pair
using namespace std;

int main()
{

ios::sync_with_stdio(0);
cin.tie(0);
ll t=1;
//cin>>t;
while(t--)
{
 ll n;
 cin>>n;
 ld ans=(ld)((n/2)+(n%2))/n;
 cout<<fixed<<setprecision(10)<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    from itertools import product
    BINGO = [[(i, j) for j in range(3)] for i in range(3)] + \
            [[(j, i) for j in range(3)] for i in range(3)] + \
            [[(0, 0), (1, 1), (2, 2)], [(0, 2), (1, 1), (2, 0)]]
    C = {A[i][j]:(i, j) for i, j in product(range(3), repeat=2)}
    D = tuple(map(lambda x: C.get(x, None), b))
    for B in BINGO:
        if all(p in D for p in B):
            return True
    return False


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(YES if solve(A, N, b) else NO)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    b *= -1;
    int sum = b + c;
    if(sum <= a && sum > 0) cout<<"safe"<<endl;
    else if(sum <= 0 && sum >= b) cout<<"delicious"<<endl;
    else cout<<"dangerous"<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <string.h>


int main(void)
  
{

  char b[4];
  
   
  scanf("%s", b);
  
  
    
  if(!strcmp(b, "A"))
   printf("T");
  
  if(!strcmp(b, "C"))
   printf("G");
  
  if(!strcmp(b, "G"))
   printf("C");
  
  if(!strcmp(b, "T"))
   printf("A");


  	return 0;
  
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a.at(i);
    }
    
    long long sum = 0;
    rep(i, n){
        sum += a.at(i);
    }
    
    cout << sum-n << endl;
    return 0;
}

Measured memory_bytes: 256
# ABC064c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
ans = 0
color = [False]*8
for i in a:
    if i >= 3200:
        ans += 1
        continue
    color[i//400] = True
print(max(color.count(True), 1), ans+color.count(True))


Measured memory_bytes: 3060
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!

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

    #pragma GCC target("popcnt")

    string to_string(const string& s) { return '"' + s + '"'; }
    void debug_out() { cout << endl; }
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) { cout << " " << to_string(H); debug_out(T...); }
    #ifdef LOCAL
        #define debug(...) cout << "#" << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    #else
        #define debug(...) 3;
    #endif

    #define fast_io ios_base::sync_with_stdio(false); \
                    cin.tie(nullptr); cout.tie(nullptr);
    using ld = long double;  using ui = uint_fast32_t;
    using ll = int_fast64_t; using ul = uint_fast64_t;

// -----------------------------------------------------------------------------

const int N = 100 + 5;
const int W = 1e5 + 5;
int n, c;
ll dp[W];

void solve() {
    cin >> n >> c;
    for (int i = 0; i < n; ++i) {
        int w, v;
        cin >> w >> v;
        for (int j = c; j >= w; --j) {
            dp[j] = max(dp[j], dp[j - w] + v);
        }
    }
    cout << *max_element(dp, dp + c + 1) << '\n';
}

// -----------------------------------------------------------------------------

int main() {
    fast_io; int t = 1;
    // cin >> t;
    // precompute();
    for (int i = 1; i <= t; ++i) solve();
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 1e2 + 9, oo = 0x3f3f3f3f;
int n, vac[N][3];
int mem[3][N];
int solve(int i, int j)
{
   if(i == n || j >= 3 || j < 0)
   {
      return 0;
   }
   else if(mem[j][i] != -1)
   {
      return mem[j][i];
   }
   int op1 = vac[i][j] + solve(i + 1, j + 1);
   int op2 = vac[i][j] + solve(i + 1, j - 1);
   int op3 = vac[i][j] + solve(i + 1, j + 2);
   int op4 = vac[i][j] + solve(i + 1, j - 2);
   //cout<<op1<<" "<<op2<<endl;
   return mem[j][i] = max(max(op1, op3), max(op2, op4));
}
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   memset(mem, -1, sizeof mem);
   cin>>n;
   int idx, mx = 0;
   for(int i = 0; i < n; i++)
   {
      for(int j = 0; j < 3; j++)
      {
         cin>>vac[i][j];
         if(mx < vac[i][j] && i == 0){
            mx = vac[i][j];
            idx = j;
         }
      }
   }
   //cout<<idx<<endl;
   cout<<solve(0, idx)<<endl;
   return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long INF = MOD*MOD;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k;
string s,s1,s2;

int main(){
  cin >> n;
  vector<int> p(n),q(n),a(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  rep(i,n) a[i] = i+1;
  int i = 1; int A, B;
  do {
    bool frag = true;
    rep(i,n) if(p[i] != a[i]) frag = false;
    if(frag) A = i;
    
    frag = true;
    rep(i, n) if(q[i] != a[i]) frag = false;
    if(frag) B = i;

    i++;
  }while( next_permutation( a.begin(), a.end() ) );

  cout << abs(A-B) << "\n";
}

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

int main() {
  int n;
  cin>>n;
  int a[100010];
  for (int i=0; i<n; i++) {
    scanf("%d",a+i);
  }

  sort(a,a+n);
  int l1=0,l2=0;
  for (int i=0; i<n;) {
    int x=a[i++];
    int cnt=1;
    for (; i<n; i++) {
      if (x==a[i])
	cnt++;
      else
	break;
    }
    if (cnt<2) continue;
    if (cnt<4) {
      l2=l1;
      l1=x;
    }
    else {
      l2=x;
      l1=x;
    }
  }

  cout<<(ll)l1*l2<<endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll n,m,S;
vector<vector<pair<int,P>>> G;
vector<ll> C,D;

void solve(){
	S = min(S,2500LL);
	vector<vector<ll>> dp(n,vector<ll>(3000,LINF));//dp[i][s] = 0からiに銀貨をs枚持って行くときかかる時間の最小値
	priority_queue<pair<ll,P>, vector<pair<ll,P>>,greater<pair<ll,P>> > q;
	dp[0][S] = 0;
	q.push(mp(0,mp(0,S)));
	while(!q.empty()){
		auto p = q.top();q.pop();
		ll time = p.fs;
		int v = p.sc.fs;
		ll s = p.sc.sc;
		if (time > dp[v][s])continue;

		if (s + C[v] <= 2500){//銀貨を追加する理由があるとき
			ll ns = s + C[v];
			ll ntime = time + D[v];
			if (chmin(dp[v][ns],ntime))q.push(mp(ntime,mp(v,ns)));
		}
		for(auto e:G[v]){
			if (s < e.second.fs)continue;//払えないとき
			int nv = e.fs;
			ll ns = s - e.second.fs;
			ll ntime = time + e.sc.sc;
			if (chmin(dp[nv][ns],ntime))q.push(mp(ntime,mp(nv,ns)));
		}

	}
	for(int i = 1; i < n; i++) {
		ll res = LINF;
		for(int s = 0; s <= 2500; s++) {
			chmin(res,dp[i][s]);
		}
		cout << res << endl;
	}
}

int main(){
	cin>>n>>m>>S;
	G.resize(n);
	for(int i = 0; i < m; i++) {
		ll u,v,a,b;cin>>u>>v>>a>>b;
		u--;v--;
		G[u].pb(mp(v,mp(a,b)));
		G[v].pb(mp(u,mp(a,b)));
	}

	for(int i = 0; i < n; i++) {
		ll c,d;cin>>c>>d;
		C.pb(c);
		D.pb(d);
	}
	solve();
	return 0;
}


Measured memory_bytes: 7420
#include<iostream>
#include<vector>
int main() {
	int n;
	while (std::cin >> n, n) {
		int N;
		std::vector<char>a(n), b(n);
		for (int i = 0; i < n; i += 1)
			std::cin >> a[i] >> b[i];
		std::cin >> N;
		std::vector<char>c(N);
		for (int i = 0; i < N; i += 1) {
			std::cin >> c[i];
			for (int j = 0; j < n; j += 1) {
				if (c[i] == a[j]) {
					c[i] = b[j];
					break;
				}
			}
		}
		for (int i = 0; i < N; i += 1) {
			if (i == N - 1)
				std::cout << c[i] << std::endl;
			else
				std::cout << c[i];
		}
	}
	return 0;
}

Measured memory_bytes: 3212
n = int(input())
a = list(map(int, input().split(' ')))

s = sum(a)
b = 0
for i in range(1, n, 2):
    b += a[i]
result = [(s-b*2)//2]
for i in range(n-1):
    result.append(a[i]-result[-1])
result = [2*i for i in result]
print(*result)

Measured memory_bytes: 15324
n = int(input())
alist = []
for i in range(n):
    a = int(input())
    alist.append(a)
aalist = sorted(alist)
ans = 0
for i in range(n):
    ans = aalist[-1]
    if alist[i] == aalist[-1]:
        ans = aalist[-2]
    print(ans)


Measured memory_bytes: 91628
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct pol{
	int X;int Y;int Z;
  bool operator<(const pol&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
int main(){
	int P,M,C;
	cin>>P>>M>>C;
	cout<<P+M+C<<endl;
	return 0;
}



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

int main()
{
	int i,j,N,v[100],ans;
	long long w[100],W,dp[101][10001];
	
	cin >> N >> W;
	
	for(i=0;i<=N-1;i++) cin >> v[i] >> w[i];
	
	for(i=0;i<=100*N;i++) dp[0][i]=1000000001;
	dp[0][0]=0;
	for(i=1;i<=N;i++)
	{
		for(j=0;j<=N*100;j++)
		{
			if(j-v[i-1]>=0) dp[i][j]=min(dp[i-1][j], dp[i-1][j-v[i-1]]+w[i-1]);
			else dp[i][j]=dp[i-1][j];
		}
	}
	for(i=0;i<=N*100;i++)
	{
		if(dp[N][i]<=W) ans=i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10964
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let line = readInts()
    let s = line[0]
    let w = line[1]
    
    if s <= w {
        print("unsafe")
    } else {
        print("safe")
    }
}

main()


Measured memory_bytes: 8240
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
const int mod=1e9+7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
int main()
{
    fastio;
    //fopen();
    int n,k,s;
    cin>>n>>k>>s;
    rep(i,n)
    {
        if(k>0){k--;cout<<s<<" ";}
        else{
            if(s!=1000000000)
            {
                cout<<s+1<<" ";
            }
            else{
                cout<<1<<" ";
            }
        }
    }
    //rep(i,n) cout<<a[i]<<" ";
    return 0;

}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

int main(){
    ll I, O, T, J, L, S, Z;
    cin >> I >> O >> T >> J >> L >> S >> Z;
    ll ans = 0;
    ans += O;
    ll i = I%2, j = J%2, l = L%2, s = i+j+l;
    ans += I+J+L-s;
    if(s == 3) ans += 3;
    elif(s == 2 && I>0 && J>0 && L>0) ans += 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int i,m;
	int a;
	int b;
	int c;
	scanf("%d %d %d",&a,&b,&c);
	
	for(i = a;i <= b;i++){
		if(c%i == 0){
			m++;
		}
	}
	
	printf("%d\n",m);

	return 0;
}


Measured memory_bytes: 2144
n = int(input())
A = []
B = []
for i in range(n):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)
A.sort()
B.sort()
if n%2 == 1:
  print(B[(n-1)//2] - A[(n-1)//2] + 1)
else:
  M = B[n//2 - 1] + B[n//2]
  m = A[n//2 - 1] + A[n//2]
  ans = M-m+1
  print(ans)

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



int main(){
    string s;
    cin >> s;
    ll k;
    cin >> k;
    char p='1';
    
    for(int i=0;i<k;i++){
        if(s[i]!='1'){
            p=s[i];
            break;
        }
    }
    cout << p << endl;
    return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>a(n),b(n);
  rep(i,0,n)cin>>a[i]>>b[i];
  bitset<30>x=k;
  rrep(i,30,0){
    if(!x[i])continue;
    else{
      ll ret=0;
      rep(j,0,n){
        bitset<30>y=a[j];
        judge=true;
        rep(o,0,30){
          if(o==i&&y[o])judge=false;
          if(o>i&&y[o]&&!x[o])judge=false;
        }
        if(judge)ret+=b[j];
        //cout<<ret spa i spa j<<endl;
      }
      //cout<<i spa ret<<endl;
      chmax(res,ret);
    }
  }

  ll ret=0;
  rep(j,0,n){
    bitset<30>y=a[j];
    judge=true;
    rep(o,0,30){
      if(y[o]&&!x[o])judge=false;
    }
    if(judge)ret+=b[j];
  }
  chmax(res,ret);


  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (b%a == 0) {
		cout << a + b << endl;
	}
	else {
		cout << b - a << endl;
	}
}

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

const int maxn = 5e3 + 10;
const long long max_val = 1LL << 62;

long long dp[maxn][maxn * 2], dp_min[maxn * 2];
int p[maxn];

long long cost(int p1, int p2, int A, int B) {
    if (p1 == p2) return 0;
    else if (p1 > p2) return B;
    else return A;
}

int main()
{
    int N, A, B, x;
    cin >> N >> A >> B;
    for (int i = 1; i <= N; i++) {
        cin >> x;
        p[x] = 2 * i - 1;
    }
    for (int i = 1; i <= N; i++) for (int j = 0; j <= 2 * N; j++) dp[i][j] = max_val;
    //dp[i][j] = min{dp[i - 1][k] + (p[i] != k) * (A | B)}
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= 2 * N; j++) {
            int tail = (j % 2 == 0 ? j : j - 1);
            dp[i][j] = dp_min[tail] + cost(p[i], j, A, B);
//            for (int k = 0; k < tail; k++) {
//                //cout << j << ' ' << k << ' ' << dp[i - 1][k] << ' ' << cost(p[i], k, A, B) << endl;
//                dp[i][j] = min(dp[i][j], dp[i - 1][k] + cost(p[i], j, A, B));
//            }
            //cout << i << ' ' << j << ' ' << dp[i][j] << endl;
        }
        dp_min[0] = dp[i][0];
        for (int j = 1; j <= 2 * N; j++) dp_min[j] = min(dp_min[j - 1], dp[i][j]);
    }
//    long long res = max_val;
//    for (int j = 0; j <= 2 * N; j++) res = min(res, dp[N][j]);
//    cout << res << endl;
    cout << dp_min[2 * N] << endl;
    return 0;
}


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

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

    int cnt_g = 0;
    int score = 0;
    rep(i, 0, s.size())
    {
        if (cnt_g == 0)
        {
            cnt_g++;
            if (s[i] == 'p')
                score--;
        }
        else
        {
            cnt_g--;
            if (s[i] == 'g')
                score++;
        }
    }
    cout << score << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=n;i>=1;i--){
		cout<<m-i+1<<" ";
	}
	for(int i=1;i<=n-1;i++){
		cout<<m+i<<" ";
	}
	return 0; 
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <bitset>
#include <fstream>

#define ll long long
#define scani(x) scanf("%i", &x)
#define scanll(x) scanf("%I64d", &x)
#define scanfl(x) scanf("%f", &x)
#define scanch(x) scanf("%c", &x)
#define scans(x) scanf("%s", x);
#define printi(x) printf("%i", x);
#define printll(x) printf("%I64d", x);
#define printfl(x) printf("%f", x);
#define printch(x) printf("%c", x);
#define prints(x) printf("%s", x);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define INFI (1 << 29)
#define INFL (1LL << 62)
#define sz(x) int(x.size())
#define fi first
#define se second
#define forn(i, n) for(ll i = 0; i < n; i++)
#define for1(i, n) for(ll i = 1; i <= n; i++)
#define ford(i, n) for(ll i = (n - 1); i >= 0; i--)
#define fori(i, n) for(ll i = n; i >= 1; i--)
#define fore(i, l, r) for(ll i = l; i <= r; i++)
#define get_bit(mask, x) (bool)(mask & (1LL << x))
#define set_bit(mask, x) (mask |= (1LL << x))
#define reset_bit(mask, x) (mask &= ~(1LL << x))
#define toggle_bit(mask, x) (mask ^= (1LL << x))

using namespace std;

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

    ll k, x;

    cin >> k >> x;

    for(ll i = (x - (k - 1)); i <= (x + (k - 1)); i++)
        cout << i << " ";
    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct quad{
  int a,b,c,d;
}A[1005];
int arr[1005];
int dfs(int cur,int N,int M,int last,int Q){
  if(cur==N-1){
    int sum=0;
    for(int i=last; i<=M; i++){
      arr[cur]=i;
      int cnt=0;
      for(int j=0; j<Q; j++){
        if(arr[A[j].b-1]-arr[A[j].a-1]==A[j].c) cnt+=A[j].d;
      }
      sum=max(sum,cnt);
    }
    return sum;
  }
  int res=0;
  for(int i=last; i<=M; i++){
    arr[cur]=i;
    res=max(dfs(cur+1,N,M,i,Q),res);
  }
  return res;
}
int main(){
  int N,M,Q;
  cin>>N>>M>>Q;
  for(int i=0; i<Q; i++){
    cin>>A[i].a>>A[i].b>>A[i].c>>A[i].d;
  }
  cout<<dfs(0,N,M,1,Q)<<endl;;
  return 0;
}


Measured memory_bytes: 3636
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        f: [[u64;10];n],
        p: [[i64;11];n]
    }

    let mut b = vec![0u64;n];
    for i in 0..n {
        for j in 0..10 {
            b[i] += f[i][j] << j;
        }
    }

    let mut x = -1i64 << 60;
    for mask in 1..1<<10 {
        let mut y = 0;
        for i in 0..n {
            y += p[i][(mask & b[i]).count_ones() as usize];
        }
        x = std::cmp::max(x, y);
    }
    println!("{}", x);
}

Measured memory_bytes: 4352
import sys


def parse(file):
    s = file.readline()
    return s,


def is_month(s):
    if (0 < int(s)) & (int(s) <= 12):
        return 1
    else:
        return 0


def main(s):
    ans = is_month(s[:2]) * 2 + is_month(s[2:])

    if ans == 0:
        return 'NA'
    elif ans == 1:
        return 'YYMM'
    elif ans == 2:
        return 'MMYY'
    elif ans == 3:
        return 'AMBIGUOUS'

    raise RuntimeError


if __name__ == '__main__':
    print(main(*parse(sys.stdin)))

Measured memory_bytes: 38384
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    for i in range(n):
        s = input()
        t = S()
        for k in s[::-1]:
            if k == "J":
                t = [t[-1]]+t[:-1]
            elif k == "C":
                t = t[1:]+[t[0]]
            elif k == "E":
                m = len(t) >> 1
                if len(t)&1:
                    t = t[m+1:]+[t[m]]+t[:m]
                else:
                    t = t[m:]+t[:m]
            elif k == "A":
                t = t[::-1]
            elif k == "M":
                for j in range(len(t)):
                    if t[j].isdecimal():
                        t[j] = str(int(t[j])+1)[-1]
            else:
                for j in range(len(t)):
                    if t[j].isdecimal():
                        if t[j] == "0":
                            t[j] = "9"
                        else:
                            t[j] = str(int(t[j])-1)
        print(*t,sep = "")
    return

#Solve
if __name__ == "__main__":
    solve()



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


int main(){
  int n;
  cin >> n;
  vector<int> a(n,0);
  for(int i = 0;i < n-1;i ++){
    int x;
    cin >> x;
    a.at(x-1)++;
  }
  
  for(int i = 0;i < n;i ++){
    cout << a.at(i) << endl;
  }
}

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

int main()
{
    int w,h,n;
    cin >> w >> h >> n;
    vector<int> x(n),y(n),a(n);
    for(int i = 0;i < n;i++) cin >> x[i] >> y[i] >> a[i];
    int left_x = 0;
    int right_x = w;
    int under_y = 0;
    int upper_y = h;
    for(int i = 0;i < n;i++){
        if(a[i] == 1 && x[i] > left_x) left_x = x[i];
        if(a[i] == 2 && x[i] < right_x) right_x = x[i];
        if(a[i] == 3 && y[i] > under_y) under_y = y[i];
        if(a[i] == 4 && y[i] < upper_y) upper_y = y[i];
    }
    int xl =  (right_x - left_x);
    int yl =  (upper_y - under_y);
    if(xl > 0 && yl > 0) cout << xl*yl << endl;
    else cout << 0 << endl;

}


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

int main() {
  int n;
  cin >> n ;
//  vector<int> in(n);
  set <int, greater <int> > inset;
  int temp;
  for(int i = 0; i<n;i++)
  {
    cin >> temp;
    inset.insert(temp);
  }
  cout << inset.size() << endl;
  
  
}


Measured memory_bytes: 256