akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef long double ld;
typedef pair<long double, long double> pld;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
    ll i, j, k;
    ll N, K;
    cin >> N >> K;
    vector<pair<ld, ld>> A;
    for(i = 0; i < N; i++) {
        ld a;
        cin >> a;
        A.push_back(pair<ld, ld>(a, 1));
    }

    ld total = 0;
    for(i = 0; i < N; i++) {
        total += (ld)A[i].first;
    }
    ll rk = K;
    ld perex = total / ((ld)N + (ld)K);
    for(i = 0; i < N; i++) {
        pld newp;
        ld nc = max(floor(A[i].first / perex) - 1, (ld)0);
        A[i].first = A[i].first / (nc + 1);
        A[i].second = nc + 1;
        rk -= nc;
    }

    priority_queue<pair<ld, ld>> q;
    for(i = 0; i < N; i++) {
        q.push(pld(A[i].first, 1));
    }

    for(i = 0; i < rk; i++) {
        pld maxlog = q.top();
        q.pop();
        pld newlog;
        newlog.first = maxlog.first * maxlog.second / (maxlog.second + 1);
        newlog.second = maxlog.second + 1;
        q.push(newlog);
    }
    ld maxld = q.top().first;
    ll ans = (ll)ceil(maxld);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 21904
n,k = map(int,input().split())
d = []
a = []
for i in range(k):
    d.append(int(input()))
    aa = list(map(int,input().split()))
    a.append(aa)

ans = [0 for i in range(n)]
for i in range(k):
    for j in range(d[i]):
        ans[a[i][j]-1] = 1

print(ans.count(0))

Measured memory_bytes: 9204
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <stack>
#include <algorithm>

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

int return_bit(int n, int k) {
  n = n >> k;
  return n & 1;
}


int main() {
  std::string S;
  std::cin >> S;
  
  int num = std::pow(2, S.size()-1);
  long long int result = 0;
  for (int i = 0; i < num; i++) {
    std::string tmp("");
    for (int k = 0; k < (int)S.size(); k++) {
      tmp += S[k];
      if (return_bit(i, k)) {
        result += std::stoll(tmp);
        tmp = "";
      } else if (k == (int)S.size()-1) {
        result += std::stoll(tmp);
      }
    }
  }

  std::cout << result << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
    int n,t;
    cin>>n>>t;
    int tn[n];
    rep(i,n)cin>>tn[i];

    int diff;
    long long ans = 0;
    rep(i,n-1){
        diff = tn[i+1] - tn[i];
        if(diff < t)ans += diff;
        else ans += t;
    }
    cout<<ans+t;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        int x, a, b;
        scanf("%d %d %d", &x, &a, &b);
        x -= a;
        printf("%d\n", x % b);
        return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <typeinfo>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>


using namespace std;


vector<vector<bool>> logics;

void dfs(vector<bool> &l1, int N) {
    vector<bool> l2 = l1;
    l1.push_back(true);
    l2.push_back(false);
    if (l1.size() == N - 1) {
        logics.push_back(l1);
        logics.push_back(l2);
    } else {
        dfs(l1, N);
        dfs(l2, N);
    }
}


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

    int N = S.size();
    int A[N];

    for (int i = 0; i < N; i++) {
        A[i] = S[i] - '0';
    }

    long long ans = 0;
    if (N == 1) {
        ans = A[0];
    } else {
        vector<bool> l0;
        dfs(l0, N);


        for (vector<bool> l: logics) {
            long long tmp = 0;
            for (int i = 0; i < N; i++) {
                tmp += A[i];
                if (i == N-1 || l[i]) {
                    ans += tmp;
                    tmp = 0;
                } else {
                    tmp = tmp*10;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}



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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, m;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    while (n != 0) {
        int p[1005] = {};
        rep(i, n) cin >> p[i];
        vector<int> score;
        score.push_back(0);
        rep(i, n) score.push_back(p[i]);
        rep(i, n) rep(j, n) {
            score.push_back(p[i] + p[j]);
        }
        sort(all(score));
        score.erase(unique(all(score)), score.end());
        int ans = 0;
        rep(i, score.size()) {
            if (score[i] > m) break;
            int l = 0;
            int r = score.size() + 1;
            while (r - l > 1) {
                int mid = (r + l) / 2;
                if (score[i] + score[mid] <= m) l = mid;
                else r = mid;
            }
            int idx = l;
            if (score[i] + score[idx] > m) continue;
            ans = max(ans, score[i] + score[idx]);
        }
        cout << ans << endl;
        cin >> n >> m;
    }
}

Measured memory_bytes: 18932
#include<stdio.h>
main(){
  int a,b,c,d,e,i,j,k,smp;
  scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
  int n[] = {a,b,c,d,e};
  for(i=0;i<5;i++){
    for(j=i+1;j<5;j++){
      if(n[i] < n[j]){
	smp = n[i];
	n[i] = n[j];
	n[j] = smp;
      }
    }
  }
  for(k=0;k<5;k++){
    if(k < 4){
      printf("%d ",n[k]);
    }
    else{
      printf("%d\n",n[k]);
    }
  } 
  return 0;
}
    

Measured memory_bytes: 596
#define rep(i,n) REP(i,0,n)
#define REP(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll MAXN = (ll)3e3+10;
const ll DIV = (ll)1e9+7;
// ll dp[MAXN][MAXN];

double dp[MAXN];
double p[MAXN];
void update(int i) {
   double dp1[MAXN]={};
   rep(j,MAXN-1) {
      dp1[j] = dp[j]*(1-p[i]);
      if(j>=1) dp1[j] += dp[j-1] *p[i];
   }
   swap(dp,dp1);
}

int main(void) {
   ll N;
   cin>>N;
   rep(i,N) cin>>p[i];
   memset(dp,0,sizeof(dp));
   dp[0] = 1;
   rep(i,N) update(i);
   double ans = 0;
   rep(i,MAXN) {
      if(i>=(N+1)/2) ans += dp[i];
   }
   printf("%.10f\n",ans);

   return 0;
}

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

void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
int cnt;
void merge(int *first, int *mid, int *last) {
    const int N1 = (int)(mid - first);
    const int N2 = (int)(last - mid);
    int *left = malloc(sizeof(int) * (N1 + 1));
    int *right = malloc(sizeof(int) * (N2 + 1));
    memcpy(left, first, sizeof(int) * (N1 + 1));
    memcpy(right, mid, sizeof(int) * (N2 + 1));
    left[N1] = right[N2] = 1000000000;
    for(int *it = first, i = 0, j = 0; it != last; ++it) {
        *it = left[i] <= right[j] ? left[i++] : right[j++];
    }
    free(left);
    free(right);
}
void merge_sort(int *first, int *last) {
    const int N = (int)(last - first);
    if(N < 2) return;
    int *mid = first + N / 2;
    merge_sort(first, mid);
    merge_sort(mid, last);
    merge(first, mid, last);
    cnt += N;
}
int main(int argc, char **argv) {
    int n = get_uint();
    int s[500001];
    for(int i = 0; i < n; ++i) s[i] = get_uint();
    merge_sort(s, s + n);
    for(int i = 0; i < n - 1; ++i) put_uint(s[i]), putchar_unlocked(' ');
    put_uint(s[n - 1]), putchar_unlocked('\n');
    put_uint(cnt), putchar_unlocked('\n');
    return 0;
}



Measured memory_bytes: 5504
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int n;
    cin >> n;
    int A[2][n];
    REP(i, 2){
        REP(j, n) cin >> A[i][j];
    }

    int ma = INT_MIN, cnt;
    REP(i, n){
        cnt = 0;
        REP(j, i + 1) cnt += A[0][j];
        FOR(j, i, n) cnt += A[1][j];
        ma = max(ma, cnt);
    }
    cout << ma << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b) {
		int ans = a + b;
		int keta = 1;
		while (ans / 10 > 0) {
			ans /= 10;
			keta++;
		}
		cout << keta << endl;
	}
	return 0;
}

Measured memory_bytes: 2984
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define M 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define tr(x,it) for(auto it = x.begin();it!=x.end();++it)
#define fpresent(x,c) ((c).find(x) != (c).end())  //set,map
#define present(c,x) (find(all(c),x) != (c).end()) //vector
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //use mt19937_64 for 64 bit random no.

int main()
{
    // freopen("input.in","r",stdin);
    // freopen("output.in","w",stdout);
    fastio;
    cin.tie(NULL);
    ll n,m,x,i,j,k,ans=1e14;
    cin>>n>>m>>x;

    vector<ll> c(n), a[n];
    for(i=0;i<n;i++){
        cin>>c[i];
        for(j=0;j<m;j++){
            cin>>k;
            a[i].pb(k);
        }
    }

    for(int mask = 0; mask < (1<<n); mask++){
        vector<ll> know(m);
        ll cost = 0;
        for(i=0;i<n;i++){
            if(mask & (1<<i))
            {
                for(j=0;j<m;j++){
                    know[j] += a[i][j];
                }
                cost += c[i];
            }
        }
        bool flag = true;
        for(i=0;i<m;i++)
            if(know[i] < x)
                flag = false;
        if(flag)
            ans = min(ans, cost);
    }
    if(ans == 1e14)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3648
from typing import List, Optional


class Node:
	def __init__(self, key) -> None:
		self.key: int = key
		self.left: Optional[Node] = None
		self.right: Optional[Node] = None
		self.parent: Optional[Node] = None


class Tree:
	def __init__(self) -> None:
		self.root: Optional[Node] = None


def insert(T: Tree, z: Node) -> None:
	y: Optional[Node] = None
	x: Optional[Node] = T.root
	while x is not None:
		y = x # 親を設定
		if z.key < x.key:
			x = x.left
		else:
			x = x.right
	z.parent = y

	if y is None:
		T.root = z
	elif z.key < y.key:
		y.left = z
	else:
		y.right = z


def find(k: int) -> Optional[Node]:
	z = T.root
	while z is not None:
		if k == z.key:
			return z
		elif k < z.key:
			z = z.left
		else:
			z = z.right
	return None

def tree_minimum(x: Node) -> Node:
	while x.left is not None:
		x = x.left
	return x


def tree_successor(x: Node) -> Node:
	if x.right is not None:
		return tree_minimum(x.right)
	y: Optional[Node] = x.parent
	while y is not None and x == y.right:
		x = y
		y = y.parent
	return y


def delete(z: Node) -> None:
	x: Optional[Node] = None
	y: Optional[Node] = None
	if (z.left is None or z.right is None):
		y = z
	else:
		y = tree_successor(z)
	if y.left is not None:
		x = y.left
	else:
		x = y.right
	if x is not None:
		x.parent = y.parent
	if y.parent is None:
		T.root = x
	elif y == y.parent.left:
		y.parent.left = x
	else:
		y.parent.right = x
	if y != z:
		z.key = y.key

def inorder(z: Optional[Node]):
	if z is not None:
		inorder(z.left)
		print(f" {z.key}", end="")
		inorder(z.right)


def preorder(z: Optional[Node]):
	if z is not None:
		print(f" {z.key}", end="")
		preorder(z.left)
		preorder(z.right)


if __name__ == "__main__":
	m = int(input())
	T = Tree()
	for _ in range(m):
		command = list(input().split())
		if command[0] == "insert":
			z = Node(int(command[1]))
			insert(T, z)
		elif command[0] == "find":
			key = int(command[1])
			z = find(key)
			if z is not None:
				print("yes")
			else:
				print("no")
		elif command[0] == "delete":
			key = int(command[1])
			z = find(key)
			if z is not None:
				delete(z)
		else:
			inorder(T.root)
			print("")
			preorder(T.root)
			print("")


Measured memory_bytes: 86816
import java.util.Scanner; // ?????¨?????????????????????

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


        // ?????????????????? int ?????¨??????????????\???????????????.
        // ????????????????????? 0 ????????????.
        int count = 0;
        while (true) {
            int x = sc.nextInt();
            if (x == 0) { break ; }
            count ++;
            System.out.println("Case " + count + ": " + x);
        }
    }
}

Measured memory_bytes: 43596
//https://atcoder.jp/contests/abc119/tasks/abc119_b

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>


using namespace std;
int main(){
	int n;
	double answer=0;

	cin >> n;
	
	vector<double> xlist(n);
	vector<string> ulist(n);

	for(int i=0; i<n; i++) cin>>xlist.at(i)>>ulist.at(i);
	
	for(int i=0; i<n; i++){
		if(ulist.at(i)=="JPY") answer+=xlist.at(i);
		else answer+=xlist.at(i)*380000;
	}
	
	cout<<answer<<endl;
}





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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int X, Y;
    cin >> X >> Y;
    REP(i, 100) {
        if (i <= X && Y == 2 * i + 4 * (X - i)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll n; read(n);
	int ans = 0;
	for (ll i = 2; i * i <= n; i++) if (n % i == 0) {
		int deg = 0;
		while (n % i == 0) n /= i, deg++;
		int j = 1;
		while (deg >= (j + 1) * (j + 2) / 2) j++;
		ans += j;
	}
	if (n != 1) ans++;
	die(ans);
}


Measured memory_bytes: 3652
/* *
 *
 * Author: Hamkor
 *
 * */
 
#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, m = 1e18; cin>>n;
	for (int i=0; i<5; ++i){
		ll x; cin>>x;
		m = min(m, x);
	}
	cout<<4ll + ((n+m-1ll)/m);
	return 0;
}


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

int main(){
	int N;
	cin >> N;
	bool if_color[8];
	int chameleon = 0;
	for(int i = 0; i < 8; i++){
		if_color[i] = false;
	}
	for(int i = 0; i < N; i++){
		int rate;
		cin >> rate;
		bool if_chose = false;
		for(int j = 0; j < 8; j++){
			if(rate < j * 400 + 400){
				if_color[j] = true;
				if_chose = true;
				break;
			}
		}
		if(!if_chose){
			chameleon++;
		}
	}
	int rate_colors = 0;
	for(int i = 0; i < 8; i++){
		rate_colors += if_color[i];
	}
	cout << max(rate_colors, 1) << " " << rate_colors + chameleon << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define Imax 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int a,b,k;
  cin>>a>>b>>k;
  int count=0;
  urep(i,100,0){
    if(a%i==0&&b%i==0){
     //cout<<i<<endl;
      count++;
      if(count==k){
        cout<<i;
        break;
      }
    }
  }
  
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include<stdio.h>

#ifndef Boolean 
#define Boolean int
#endif

#ifndef TRUE       
#define TRUE 1
#endif

#ifndef FALSE 
#define FALSE 0
#endif

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

int main(){
  int q,M,i;
  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);
    if(solve(0,M))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

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

int main() {
    int M = 3;
    vector<vector<int>> A(M, vector<int>(M));
    rep(i, M) rep(j, M) cin >> A[i][j];
    int N; cin >> N;
    set<int> st;
    rep(i, N) {
        int b; cin >> b;
        st.insert(b);
    }
    bool ok = false;
    rep(i, M) {
        bool all = true;
        rep(j, M) {
            if(st.count(A[i][j]) == 0) all = false;
        }
        if(all) ok = true;
    }
    rep(i, M) {
        bool all = true;
        rep(j, M) {
            if(st.count(A[j][i]) == 0) all = false;
        }
        if(all) ok = true;
    }
    bool all = true;
    rep(i, M) {
        if(st.count(A[i][i]) == 0) all = false;
    }
    if(all) ok = true;
    all = true;
    rep(i, M) {
        if(st.count(A[i][2 - i]) == 0) all = false;
    }
    if(all) ok = true;
    cout << (ok ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Dice2 dice = new Dice2();
		int n = scan.nextInt();
		for(int i = 0 ; i < 6 ; i ++){
			dice.d[i]=scan.nextInt();
		}
		for(int i = 0 ; i < n-1 ; i ++){
			for(int j = 0 ; j < 6 ; j ++){
				dice.d2[j]=scan.nextInt();
			}
			dice.check();
		}
		System.out.println(dice.result);
	}
}
class Dice2{
	public int[] d = new int[6];
	public int[] d2 = new int[6];
	private int temp=0;	
	public String result = "Yes"; 
	void N(){
		temp=d[0];
		d[0]=d[1];
		d[1]=d[5];
		d[5]=d[4];
		d[4]=temp;
	}
	void S(){
		temp=d[0];
		d[0]=d[4];
		d[4]=d[5];
		d[5]=d[1];
		d[1]=temp;
	}
	void E(){
		temp=d[0];
		d[0]=d[3];
		d[3]=d[5];
		d[5]=d[2];
		d[2]=temp;
	}
	void W(){
		temp=d[0];
		d[0]=d[2];
		d[2]=d[5];
		d[5]=d[3];
		d[3]=temp;
	}
	void R(){
		temp=d[1];
		d[1]=d[2];
		d[2]=d[4];
		d[4]=d[3];
		d[3]=temp;
	}
	void check(){
		for(int i = 0 ; i <= 3 ; i ++){
			if(checkAll()){
				break;
			}
			N();
			for(int j = 0 ; j <= 3 ; j ++){
				if(checkAll()){
					break;
				}
				R();
			}
		}
		for(int j = 0 ; j <= 3 ; j ++){
			if(checkAll()){
				break;
			}
			W();
			for(int i = 0 ; i <= 3 ; i ++){
				if(checkAll()){
					break;
				}
				R();
			}
		}
		if(Arrays.equals(d,d2)){
			result="No";
		}
	}
	boolean checkAll(){
		if(d[0] == d2[0] && d[1] == d2[1] && d[2] == d2[2] &&
				d[3] == d2[3] && d[4] == d2[4] && d[5] == d2[5]){
			return true;
		}
		return false;
	}
}

Measured memory_bytes: 20908
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
const long long int pl=1000000;

long long int N,K,p[200002],sum=0;
string str;

int main(){

    cout << fixed << setprecision(18);
    cin>>N;
    N--;
    while(N>=26){
        str=(char)(N%26+'a')+str;
        N/=26;
        N--;
    }
    str=(char)(N%26+'a')+str;
    cout<<str<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define MAX 100005
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define fastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define scan(a) scanf("%d", &a)
#define scanll(a) scanf("%lld", &a)
#define scanD(a) scanf("%lf", &a)
#define print(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printD(a) printf("%lf\n", a)
#define printTwo(a) printf("%.2lf\n", a);
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

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

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)
#define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

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

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
	typedef string::iterator si;
	static void call(si it, si ed) {}
	template<typename T, typename ... aT>
	static void call(si it, si ed, T a, aT... rest) {
		string b;
		for(; *it!=','; ++it)
			if(*it!=' ')
				b+=*it;
		cout << b << "=" << a << " ";
		call(++it, ed, rest...);
	}
};

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


void solve() {
	ll n, k;
	scanll(n);
	scanll(k);
	if(n % k == 0) {
		print(0);
	} else if(n <= k) {
		printll(min(n, abs(n - k)));
	} else {
		ll ans = n / k;
		n = n - ans * k;
		printll(min(n, abs(n - k)));
	}
}


int main() {
#ifdef Niloy
	read("input.txt");
	write("output.txt");
#endif

	solve();

	// __test {
	// 	solve();
	// }

	showTime;
	return 0;
}




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

#define P pair<int, int>

typedef long long ll;

using namespace std;


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

	int ans = 1e9;
	for (int i = 0; i <= 3; i++) {
		int from = i;
		int cnt = i;
		for (int j = 0; j < N; j++) {
			int plus = max(0, p[j] - from);
			cnt += (j == N - 1 ? 1 : 2)*plus;
			from = plus;
		}
		ans = min(ans, cnt);
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3132
import fractions
 
a,b,c,d = map(int,input().split())
 
ans = 0
 
if c % d == 0:
    print((b - a + 1) - ((b)//d - (a-1)//d))
elif d % c == 0:
    print((b - a + 1) - ((b)//c - (a-1)//c))
else:
    tot = c * d // fractions.gcd(c, d)
    tmp = ((b) // d - (a-1) // d) + ((b)//c - (a-1)//c) - ((b) // tot - (a-1) // tot)
    print(int((b - a + 1) - tmp))

Measured memory_bytes: 5052
#include <cstdio>
#include <cstring>
#define MAXN 1000010
#define LL long long

int n;
LL L,T;
LL pos[MAXN],dir[MAXN];
LL d1[MAXN],d2[MAXN];
LL sd1[MAXN],sd2[MAXN];
LL p1[MAXN],p2[MAXN];
int id1[MAXN],id2[MAXN];
int target1[MAXN],target2[MAXN],target[MAXN];
int n1,n2;

LL getD1(int x,int l){
	if(l<=x) return sd1[x]-sd1[x-l];
	LL res=sd1[x];
	l-=x;
	res+=sd1[n1]*(l/n1);
	res+=sd1[n1]-sd1[n1-l%n1];
	return res;
}

LL getD2(int x,int l){
	if(l<=n2-x+1) return sd2[x+l-1]-sd2[x-1];
	LL res=sd2[n2]-sd2[x-1];
	l-=n2-x+1;
	res+=sd2[n2]*(l/n2);
	res+=sd2[l%n2];
	return res;
}

int find1(int x1,int x2,LL t){
	int l=0,r=t;
	while(l<r){
		int mid=(l+r+1)>>1;
		if(getD1(x1,mid)+getD2(x2,mid)<=t) l=mid;
		else r=mid-1;
	}
	t-=getD1(x1,l)+getD2(x2,l);
	x1=((x1-l-1)%n1+n1)%n1+1;
	x2=(x2+l-1)%n2+1;
	if(t<d1[x1]) return id2[x2];
	else return id1[(x1-2+n1)%n1+1];
}

int find2(int x1,int x2,LL t){
	int l=0,r=t;
	while(l<r){
		int mid=(l+r+1)>>1;
		if(getD1(x1,mid)+getD2(x2,mid)<=t) l=mid;
		else r=mid-1;
	}
	t-=getD1(x1,l)+getD2(x2,l);
	x1=((x1-l-1)%n1+n1)%n1+1;
	x2=(x2+l-1)%n2+1;
	if(t<d2[x2]) return id1[x1];
	else return id2[x2%n2+1];
}

int main(){
#ifdef DEBUG
	freopen("C.in","r",stdin);
#endif
	scanf("%d%lld%lld",&n,&L,&T);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",pos+i,dir+i);
		if(dir[i]==1){
			p1[++n1]=pos[i];
			id1[n1]=i;
		}else{
			p2[++n2]=pos[i];
			id2[n2]=i;
		}
	}
	for(int i=1;i<=n1;i++){
		d1[i]=(p1[i]-p1[(i-2+n1)%n1+1]+L)%L;
		if(!d1[i]) d1[i]=L;
		sd1[i]=sd1[i-1]+d1[i];
	}
	for(int i=1;i<=n2;i++){
		d2[i]=(p2[i%n2+1]-p2[i]+L)%L;
		if(!d2[i]) d2[i]=L;
		sd2[i]=sd2[i-1]+d2[i];
	}
	T*=2;
	int now=1;
	for(int i=1;i<=n1;i++){
		if(!n2){
			target[i]=i;
			continue;
		}
		while(now<=n2 && p1[i]>p2[now]) now++;
		int x=(now-1)%n2+1;
		LL delta=(p2[x]-p1[i]+L)%L;
		if(delta>T) target1[i]=id1[i];
		else target1[i]=find1(i,x,T-delta);
		target[id1[i]]=target1[i];
	}
	now=n1;
	for(int i=n2;i>=1;i--){
		if(!n1){
			target[i]=i;
			continue;
		}
		while(now && p2[i]<p1[now]) now--;
		int x=(now-1+n1)%n1+1;
		LL delta=(p2[i]-p1[x]+L)%L;
		if(delta>T) target2[i]=id2[i];
		else target2[i]=find2(x,i,T-delta);
		target[id2[i]]=target2[i];
	}
	T/=2;
	for(int i=1;i<=n;i++){
		int x=target[i];
		if(dir[x]==1) printf("%lld\n",(pos[x]+T)%L);
		else printf("%lld\n",((pos[x]-T)%L+L)%L);
	}
	return 0;
}


Measured memory_bytes: 30208
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int c,n,i,f=0;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            if(a[i]%3!=0 && a[i]%5!=0)
            {f=-1;
            break;}
        }
    }
    if(f==-1)
    cout<<"DENIED";
    else
    cout<<"APPROVED";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  int i, j;
  vector<int> K(N, 0);
  for(i=1; i<=N-1; i++){
    for(j=i+1; j<=N; j++){
      int r1 = j - i;
      int r2 = abs(Y-j) + 1 + abs(i-X);
      K[min(r1, r2)]++;
    }
  }
  for(i=1; i<N; i++){
    cout << K[i]<< endl;
  }
  return 0;
}


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

int main() {
    string word;
    stack<int> S;
    while (cin >> word) {
        if (word == "+") {
            int a = S.top(); S.pop();
            int b = S.top(); S.pop();
            S.push(a+b);
        }
        else if (word == "-") {
            int a = S.top(); S.pop();
            int b = S.top(); S.pop();
            S.push(b-a);
        }
        else if (word == "*") {
            int a = S.top(); S.pop();
            int b = S.top(); S.pop();
            S.push(a*b);
        }
        else {
            //S.push(stoi(word));
            S.push(atoi(word.c_str()));
        }
    }
    cout << S.top() << endl;
    return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k;
	int a,b;
	cin >> k >> a >> b;
	int p = a/k;
	if(a%k)p++;
	int q = b/k;
	if(q>=p)cout << "OK";
	else cout << "NG";
	return 0;
} 

Measured memory_bytes: 3636
case class Dice(top: Int, s: Int, e: Int, w: Int, n: Int, bottom: Int) {
  def rollToE = Dice(w, s, top, bottom, n, e)
  def rollToN = Dice(s, bottom, e, w, top, n)
  def rollToS = Dice(n, top, e, w, bottom, s)
  def rollToW = Dice(e, s, bottom, top, n, w)
}


object Main extends App {

  val sc = new java.util.Scanner(Console.in)

  def next() = sc.next()
  def nextInt() = next().toInt

  val start = Dice(nextInt(), nextInt(), nextInt(), nextInt(), nextInt(), nextInt())

  val commands = next()

  val end = commands.foldLeft(start) {
    case (dice, 'E') => dice.rollToE
    case (dice, 'N') => dice.rollToN
    case (dice, 'S') => dice.rollToS
    case (dice, 'W') => dice.rollToW
  }

  println(end.top)
}



Measured memory_bytes: 45088
import java.util.*;
public class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in); 
    int n  = sc.nextInt();
    
    int b = 0;
    int c = 0;
    int d = 0;
    int e = 0;

    
    for(int i = 0; i < n; i++)
    {
      String str = sc.next();
      if(str.equals("AC"))
          b++;
      if(str.equals("WA"))
    		  {
          c++;
    		  }
      if(str.equals("TLE"))
          d++;
      if(str.equals("RE"))
          e++;
    }
    System.out.println("AC x "+b);
    System.out.println("WA x "+c);
    System.out.println("TLE x "+d);
    System.out.println("RE x "+e);
  }
}                          


Measured memory_bytes: 58776
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <ios>
using namespace std;
//#define DEBUG
#ifdef DEBUG
#define dump(x) cout << "[*] " #x ": " << x << endl
#define debug(x) x
#else
#define dump(x)
#define debug(x)
#endif

#define int long long
typedef long long ll;
//constexpr int INF = 1e9;
//constexpr int MOD = 1000000007;

/* MOD MEMO
 * add,sub,mul: 途中でも OK
 * div: a / b => a * b^{-1} (mod p)
 */
template <typename T>
constexpr T mod(const T val, const T m) {
    T ret = val % m;
    if (ret < 0) ret += m;
    return ret;
}
template <typename T>
T modinv(T a, T m) {
    T b = m, u = 1, v = 0;
    while (b) {
        T t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u = mod(u, m);
    return u;
}
template <typename T>
T modpow(T a, T n, T mod) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
class ModCombination
{
    vector<ll> fac, finv, inv;
public:
    ModCombination(int N, ll mod)
        :fac(N+1), finv(N+1), inv(N+1)
    {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < N; ++i) {
            fac[i] = fac[i-1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod/i) % mod;
            finv[i] = finv[i-1] * inv[i] % mod;
        }
    }
    ll operator()(int n, int k, ll mod) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
    }
};

decltype(1) main() {
    //cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }

    int sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += b[i] - a[i];
    }
    if (sum < 0) {
        cout << "No" << endl;
        return 0;
    }

    int need1 = 0;
    int need2 = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] > b[i]) {
            need1 += a[i] - b[i];
        } else {
            need2 += (b[i] - a[i] + 1) / 2;
        }
    }
    if (sum >= max(need1, need2)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P);
P dequeue(void);


int main(){
  int elaps = 0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n+1;
  
  while(head != tail){
    if(Q[head].t<=q){
      elaps += Q[head].t;
      u=dequeue();
      printf("%s %d\n",u.name,elaps);
    }else{
      elaps += q;
      Q[head].t -= q;
      enqueue(Q[head]);
      dequeue();
    }
  }  

 
  return 0;
  
}

void enqueue(P x){ 
  Q[tail]=x;
  if(tail==LEN){
    tail = 1;
  }else{
    tail++;
  }
}

P dequeue(){
  P x;
  x = Q[head];
  if(head == LEN){
    head = 1;
  }else{
    head++;
  }
  return x; 
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
using namespace std;
int main(){
    string s,t;
    cin>>s;
    cin>>t;
    int S=s.length(),T=t.length();
    if(S<T){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    string ans(60,'z');
    int made=0;
    rep(i,0,S-T+1){
        if(s[i]!='?'&&s[i]!=t[0])continue;
        int ok=1;
        rep(j,0,T){
            if(s[i+j]!='?'&&s[i+j]!=t[j]){
                 ok=0;
                 break;
            }
        }
        if(ok){
            made=1;
            string buf;
            rep(k,0,S){
                if(k==i){
                    rep(l,0,T)buf+=t[l];
                    k+=T-1;
                }
                else if(s[k]=='?')buf+='a';
                else buf+=s[k];
            }
            ans=(((ans.compare(buf))>0)?(buf):(ans));
        }
    }
    if(made)cout<<ans<<endl;
    else cout<<"UNRESTORABLE"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a>=1 && b>=1 && c>=1 && a<=10 && b<=10 && c<=10)
	{
		if(a+b+c==17 && a*b*c==175)
		{
			printf("YES");
		}
		else
		{
			printf("NO");	
		}
	}
	else
	{
		printf("input error");
	}
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  int w,h,n;
  cin >> w >> h >> n;
  vector<int> x(n);
  vector<int> y(n);
  REP(i,n) cin >> x[i] >> y[i];
  int sum = 0;
  REP(i,n-1) {
    bool f = false;
    if(x[i] > x[i+1]) {
      swap(x[i],x[i+1]);
      swap(y[i],y[i+1]);
      f = true;
    }
    if (y[i] > y[i+1]) {
      sum += y[i]-y[i+1] + x[i+1]-x[i];
    } else {
      sum += max(y[i+1]-y[i],x[i+1]-x[i]);
    }
    if(f) {
      swap(x[i],x[i+1]);
      swap(y[i],y[i+1]);
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1204
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,w;
  cin>>n>>w;
  vector<ll> weight(n),value(n);
  rep(i,n) cin>>weight[i]>>value[i];
  ll dp[n+1][w+1];
  rep(i,w+1) dp[0][i]=0;
  rep(i,n){
    rep(j,w+1){
      if(j-weight[i]>=0) dp[i+1][j]=max(dp[i][j],dp[i][j-weight[i]]+value[i]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  cout<<dp[n][w]<<endl;
  
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  string s;
  cin >> n >> s;
  int x = 0, ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'I') {
      x++;
    } else {
      x--;
    }

    ans = max(ans, x);
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3572
s = input()

max_len = 0
len = 0
for e in s:
    if e == 'A' or e == 'C' or e == 'G' or e == 'T':
        len += 1
    else:
        if max_len < len:
            max_len = len
        len = 0

if max_len < len:
    max_len = len
print(max_len)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int dp[200001][2];

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

	string s;
	cin >> s;
	if (s.size() == 1) {
		cout << 1 << endl;
		return 0;
	}


	memset(dp, -1, sizeof(dp));
	dp[1][0] = 1;
	dp[2][1] = 1;


	for (int i = 1; i < s.size(); i++) {
		rep(j, 2)if (dp[i][j] != -1) {

			if (j == 1 || s[i - 1] != s[i]) {
				dp[i + 1][0] = max(dp[i + 1][0], dp[i][j] + 1);
			}


			if (i + 2 <= s.size() && (j == 0 || s[i - 2] != s[i] || s[i - 1] != s[i + 1])) {
				dp[i + 2][1] = max(dp[i + 2][1], dp[i][j] + 1);
			}
		}
	}

	cout << max(dp[s.size()][0], dp[s.size()][1]) << endl;


	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int j = 0; j < m; ++j) {
    cin >> s[j] >> c[j];
    --s[j];
  }
  for (int x = 0; x < 1000; ++x) {
    auto t = to_string(x);
    if ((int)t.size() != n) {
      continue;
    }
    bool ok = true;
    for (int j = 0; j < m; ++j) {
      if (t[s[j]] - '0' != c[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << x << '\n';
      exit(0);
    }
  }
  cout << "-1\n";
}


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

using namespace std;
//vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000'000'007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//




int main() {
    IOS

    ll n, k;
    cin >> n >> k;
    if (k == 1) {
        cout << 0;
        return 0;
    } else {
        cout << n - k;
    }
    return 0;
}

Measured memory_bytes: 256