akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int N = sc.nextInt();
        final int Q = sc.nextInt();
        
        // i行目において右方向にひっくり返せる黒い石の数。
        // j列目において下方向にひっくり返せる黒い石の数。
        // 但し黒い石のみに着目するため、座標系は [0, N-2)。
        int[] horizontallyAvailables = new int[N - 2];
        int[] verticallyAvailables = new int[N - 2];
        for (int i = 0; i < N - 2; i++) {
            horizontallyAvailables[i] = N - 2;
            verticallyAvailables[i] = N - 2;
        }
        
        // 盤上に残っている黒い石の数。
        long blacks = ((long) N - 2) * (N - 2);
        
        int minHorizontal = N - 2;
        int minVertical = N - 2;
        
        for (int i = 0; i < Q; i++) {
            boolean isVertical = sc.nextInt() == 1;
            int idx = sc.nextInt() - 2;
            
            if (isVertical) {
                if (idx < minVertical) {
                    for (int j = idx; j < minVertical; j++) {
                        verticallyAvailables[j] = minHorizontal;
                    }
                    minVertical = idx;
                }
                
                blacks -= verticallyAvailables[idx];
                
            } else {
                if (idx < minHorizontal) {
                    for (int j = idx; j < minHorizontal; j++) {
                        horizontallyAvailables[j] = minVertical;
                    }
                    minHorizontal = idx;
                }
                
                blacks -= horizontallyAvailables[idx];
            }
        }
        
        System.out.println(blacks);
    }
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;

long long int n,cnt=0,ans=0,a[1000],b,c,d,cmp[4],cmpp,m,h,w,x,y,sum=0,pos,dp[51][50*100+200],p;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------
int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
     
    cin>>n>>p;
    rep(i,n)cin>>a[i],sum+=a[i];
    //rep(i,n)dp[i+1][0]=1;
    dp[0][0]=1;
    rep(i,n){
      rep(j,sum+1){
        dp[i+1][j]+=dp[i][j];
        if(j>=a[i])dp[i+1][j]+=dp[i][j-a[i]];
      }
    }
    rep(i,sum+1){
      if(i%2==p)ans+=dp[n][i];
    }
  Cout(ans);
       
return 0;
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
	private static Scanner sc=new Scanner(System.in);
	public static void main(String[] args){
		long x=sc.nextLong();
		long ans=0;
		if((x%11)>6){
			ans=(x/11)*2+2;
		}else if((x%11)>0){
			ans=(x/11)*2+1;
		}else if((x%11)==0){
			ans=(x/11)*2;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22356
#include<iostream>
using namespace std;
int main(){
    int n,m,a[100];
    int f[100][100];
    int cnt[100]{0};
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            cin>>f[i][j];
        }
    }
    
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(f[i][j]==a[i]){
                cnt[j]++;
            }else{
                cnt[a[i]-1]++;
            }
        }
    }
    for(int j=0;j<n;j++){
        cout<<cnt[j]<<endl;
    }

    return 0;
}

Measured memory_bytes: 3068
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a,b;
        while(true){
            a = scan.nextInt();
            b = scan.nextInt();
            
            if(a == 0 && b == 0)
                return;
            if( a< b)
                System.out.printf("%d %d\n",a,b);
            else
                System.out.printf("%d %d\n",b,a);

        }

    }
}


Measured memory_bytes: 40216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int h,w;
	cin>>h>>w;
	vector<string> s(h);
	rep(i,h){
		cin>>s[i];
	}
	vector<int> dx={1,-1,0,0},dy={0,0,1,-1};
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='#'){
				bool flag=false;
				rep(k,4){
					int nx=i+dx[k],ny=j+dy[k];
					if(0<=nx && nx<h && 0<=ny && ny<w){
						if(s[nx][ny]=='#'){
							flag=true;
						}
					}
				}
				if(!flag){
					cout<<"No"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"Yes"<<endl;
}

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

typedef long long int ll;

int main() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (auto& i : v) cin >> i;

    ll sum = 0;
    for (auto i : v) sum += i;

    if (sum % (n * (n + 1) / 2)) {
        cout << "NO" << endl;
        return 0;
    }

    ll k = sum / (n * (n + 1) / 2);
    for (int i = 0; i < n; i++) {
        ll d = v[(i+1)%n] - v[i] - k;
        if(d > 0 || (-d) % n) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 1024
// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

constexpr ll MOD = 1000000007;

ll N;

bool PRIME[1001];
void eratosthenes()
{
    fill(begin(PRIME), end(PRIME), true);

    PRIME[0] = PRIME[1] = false;

    int n = NELEMS(PRIME) - 1;
    int isqrt = static_cast<int>(sqrt(n));
    FOR(i, 2, isqrt+1) {
        if(PRIME[i]) {
            for(int j = 2*i; j <= n; j += i) {
                PRIME[j] = false;
            }
        }
    }
}

void solve()
{
    eratosthenes();

    ll pw[1001] = {};
    FOR(k, 2, N+1) {
        int k2 = k;
        int p_max = k2;
        FOR(p, 2, p_max+1) {
            if(!PRIME[p]) continue;
            while(k2 % p == 0) {
                ++pw[p];
                k2 /= p;
            }
        }
    }
#ifdef DEBUG
    PRINT_RANGE(pw, pw+N+1);
#endif

    ll cnt = 1;
    FOR(p, 2, N+1) {
        cnt *= pw[p] + 1;
        cnt %= MOD;
    }

    cout << cnt << "\n";
}

int main()
{
    cin >> N;

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

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

  int N, a;
  cin >> N;
  int cnt = 0, num = 1;
  for(int i = 0; i < N; i++) {
    cin >> a;
    a == num ? num++ : cnt++;
  }
  cout << (cnt == N ? -1 : cnt) << endl;
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n>>i;
    cout<<n-i+1<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	LL N;
	cin >> N;

	vector<LL> A(5);
	for (int i = 0; i < 5; ++i) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	LL ans = (N + A[0] - 1) / A[0] + 4;
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
from math import sqrt


def _2017_like_number(Q: int, queries: list) -> list:
    N = 10 ** 5
    prime_numbers, prime_count = [], 0

    def is_prime(n: int) -> bool:
        if n < 2:
            return False

        sq = int(sqrt(n)) + 1
        for p in prime_numbers:
            if sq < p:
                break
            if n % p == 0:
                return False

        return True

    def is_prime_use_list(n: int) -> bool:
        l, r = 0, prime_count
        while r - l > 1:
            m = (l + r) // 2

            if prime_numbers[m] <= n:
                l = m
            else:
                r = m

        return prime_numbers[l] == n

    S = [0] * (N + 1)
    for i in range(0, N):
        S[i + 1] = S[i]

        if is_prime(i + 1):
            prime_numbers.append(i + 1)
            prime_count += 1
        else:
            continue

        if is_prime_use_list((i+2)//2):
            S[i + 1] += 1

    return [S[r] - S[l - 1] for l, r in queries]


if __name__ == "__main__":
    Q = int(input())
    queries = [tuple(int(s) for s in input().split()) for _ in range(Q)]
    ans = _2017_like_number(Q, queries)
    for a in ans:
        print(a)


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

int main(){
    int N ;
    cin >> N ;
    vector<int> P(N);
    vector<int> Q(N);
    vector<int> R(N);
    rep(i,N) cin >> P[i];
    rep(i,N) cin >> Q[i];
    rep(i,N) R[i] = i + 1 ;
    int A = 0, B = 0 ,cnt = 0;
    do{
        int k = 0 ;
        if(P == R) A = cnt ;
        if(Q == R) B = cnt;
        cnt ++ ;

    }while(next_permutation(R.begin(), R.end()));
    cout <<  abs(A-B) << endl;
    
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int,input().split()))
total = 1000
for i in range(n-1):
    if arr[i] < arr[i+1]:
        stocks = total // arr[i]
        total += (arr[i+1] - arr[i]) * stocks
print(total)

Measured memory_bytes: 9116
N=int(input())
L=[2]*(N+1)
L[1]=1
for i in range(2,N):
  j=i*2
  while j<=N:
    L[j]+=1
    j+=i
ans=0
for i in range(1,N+1):
  ans+=L[i]*i
print(ans)
     
               

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

int main() {
    int n;
    scanf("%d", &n);
    int s[n];
    rep(i, n) scanf("%d", &s[i]);
    int q;
    scanf("%d", &q);
    int t[q];
    rep(i, q) scanf("%d", &t[i]);
    int c = 0;
    rep(i, q) {
        rep(j, n) {
            if (t[i] == s[j]) {
                c++;
                break;
            }
        }
    }
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,K;cin >> N >> K;
    vector<LL> V(N);
    rep(i,N)cin >> V[i];

    LL res = 0;
    for(int p = 0;p <= min(N,K);++p){
        for(int q = 0;p + q <= min(N,K);++q){
            vector<LL> get;
            LL cur = 0;
            rep(i,p)get.push_back(V[i]),cur += V[i];            // 左からとり続ける
            rep(i,q)get.push_back(V[N-1-i]),cur += V[N-1-i];    // 右からとり続ける

            sort(all(get));
            for(int i = 0;i < min(K-p-q,(int)get.size());++i){  // 残り回数か、もしくはとった分だけ元に戻す。 
                if(get[i] < 0)cur -= get[i];
            }
            res = max(res,cur);
        }   
    }

    cout << res << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
#define MOD 1e9 + 7
#define N 1e5 + 10
struct dish
{
	ll rem,t;
};
bool cmp(dish a,dish b)
{
	return(a.rem>b.rem);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	dish d[5];
	ll i=0;
	for(i=0;i<5;i++)
	{
		cin>>d[i].t;
		d[i].rem=d[i].t%10;
		if(d[i].rem==0)
			d[i].rem=10;
	}
	sort(d,d+5,cmp);
	ll sum=0;
	for(i=0;i<4;i++)
	{
		if(d[i].rem==10)
		{
			sum+=d[i].t;
		}
		else
		{
			sum+=(ceil((d[i].t*1.0)/10))*10;
		}
	}
	sum+=d[4].t;
	cout<<sum;

}	

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
const int N=2001;
int n,m,_m,a[N],A[N],b[N][10],t[N*10],fa[N*10];bool v[N*10],f[N];
bool pri(int x,int y){return y?pri(y,x%y):(x==1);}
bool cmp(int x,int y){return b[x/10][x%10]<b[y/10][y%10];}
int ask(int x){return fa[x]==x?x:fa[x]=ask(fa[x]);}
void unite(int x,int y){x=ask(x),y=ask(y);if(y!=x)fa[y]=x;}
int main(){
	scanf("%d",&n);
	ref(i,1,n)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	ref(i,1,n){
		int S=a[i],s=(int)sqrt(a[i]);
		ref(j,2,s)if(S%j==0){
			while(S%j==0)S/=j;
			b[i][++b[i][0]]=j;
		}
		if(S>1)b[i][++b[i][0]]=S;
		ref(j,1,b[i][0])t[++m]=i*10+j;
		A[i]=a[i];a[i]=i;
	}
	sort(t+1,t+m+1,cmp);_m=n;
	for(int i=1,la=-1;i<=m;++i){
		int&s=b[t[i]/10][t[i]%10];
		_m+=(s!=la);la=s;s=_m;
	}m=_m;
	ref(i,1,n){
		int tot=0,p=0,ap=0;
		ref(j,1,m)fa[j]=j,v[j]=0;
		ref(j,i,n)ref(I,1,b[a[j]][0])
			unite(j,b[a[j]][I]);
		ref(j,i,n)if(ask(j)==j)tot++;
		ref(j,i,n)if(!v[ask(j)]&&!f[a[j]]){
			v[ask(j)]=1,tot--;
			if(tot==0){p=j;break;}
		}
		ap=a[p];
		for(int j=p;j>i;--j)a[j]=a[j-1];
		a[i]=ap;
		ref(j,i+1,n){
			int x=A[a[i]],y=A[a[j]];
			if(x<y){
				f[a[j]]=pri(x,y);
			}else{
				f[a[j]]=f[a[j]]&&pri(x,y);
			}
		}
	}
	ref(i,1,n)printf("%d ",A[a[i]]);
}

Measured memory_bytes: 384
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
map<int, int> wow;
int main() {
	int n,m;
	cin >> n;
	REP(i, n) {
		int a;
		cin >> a;
		wow[a]++;
	}
	cin >> m;
	REP(i, m) {
		int a;
		cin >> a;
		wow[a]--;
		if (wow[a] < 0) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int,int> vii;
typedef vector<ll,ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
ll m,k,dua[30];
deque <ll> q;
int main(){
//    for(int i=1;i<=30;i++){
//        int sum = 0;
//        for(int j=1;j<=i;j++){
//            sum = sum xor j;
//        }
//        if(i==sum-1){cout<<i<<endl;}
//    }
    dua[0] = 1;
    for(int i = 1;i <= 25;i++){
        dua[i] = 2 * dua[i-1];
    }
    cin>>m>>k;
    if(k==0){
        for(int i=0; i < dua[m]; i++){
            cout<<i<<" "<<i;
            if(i==dua[m]-1){cout<<endl;}
            else{cout<<" ";}
        }
    }
    else if(m==1){cout<<-1<<endl;}
    else{
        if(k > dua[m]-1){cout<<-1<<endl;}
        else{
            q.push_front(k);
            for(int i=0;i<dua[m];i++){
                if(i==k)continue;
                q.push_back(i);
                q.push_front(i);
            }
            cout<<k;
            while(!q.empty()){
                cout<<" "<<q.front();
                q.pop_front();
            }
            cout<<endl;
        }
    }

}



Measured memory_bytes: 3968
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e5+5;
int pa[maxn];
int Mrk[maxn];

int qt[maxn],qv[maxn];
int Qt;
int fdst(int x)
{
    return Mrk[x] < Qt ? x :pa[x] = fdst(pa[x]);
}

//#define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    int N, Q;
    while(scanf("%d%d",&N,&Q),N){
        for(int i = 2; i <= N; i++){
            scanf("%d",pa+i);
            Mrk[i] = Q+1;
        }
        int c = 0;
        for(int i = 1; i <= Q; i++){
            char op[2];
            int v;
            scanf("%s%d",op,&v);
            if(*op == 'Q'){
                qt[c] = i;
                qv[c++] = v;
            }else {
                Mrk[v] = min(Mrk[v],i);//取最早生效的??
            }
        }
        long long ans = 0;
        while(c--){
            Qt = qt[c];
            ans += fdst(qv[c]);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 2508
N,M = map(int,input().split())

sc = []
for i in range(M):
    s,c = map(int,input().split())
    c = str(c)
    sc.append([s-1,c])

for i in range(10**N+1):
    tmp = str(i)
    flag = False
    count = 0
    if len(tmp) == N:
        for s,c in sc:
            if tmp[s] == c:
                count += 1
        if count == M:
            flag = True
    if flag:
        print(tmp)
        exit()
print(-1)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <cmath>

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N;
    cin >> N;
    int K;
    cin >> K;
    vector<ll> X(N);
    for(int i = 0; i < N; i++) cin >> X[i];
    
    ll ans = L_INF;
    for(int i = 0; i < N - K + 1; i++){
        ll go = min(abs(X[i]), abs(X[i + K - 1]));
        ll back = X[i + K - 1] - X[i];
        ans = min(ans, go + back);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<int, int>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N, M; cin >> N >> M;
  vector<int> p(M), y(M);
  rep(i, M) cin >> p[i] >> y[i];
  rep(i, M) --p[i];

  vector<vector<P>> que(N);
  rep(i, M){
    que[p[i]].push_back(make_pair(y[i], i));
  }
  rep(i, N){
    sort(que[i].begin(), que[i].end());
  }

  vector<string> ans(M);
  rep(i, N){
    string str = to_string(i + 1);
    while (str.length() != 6) str = '0' + str;
    int n_city = 1;
    for (auto e: que[i]){
      string str2 = to_string(n_city);
      while (str2.length() != 6) str2 = '0' + str2;
      ans[e.second] = str + str2;
      n_city++;
    }
  }
  rep(i, M) cout << ans[i] << endl;
}


Measured memory_bytes: 12708
#include<stdio.h>
#include<math.h>

int main(void)
{
	long long int n;
	long long int i = 2;
	scanf("%lld",&n);
	printf("%lld:",n);

	while (n != 1) {
		if (n%i == 0) {
			n /= i;
			printf(" %lld",i);
		}
		else if (i > sqrt(n)) {
			printf(" %lld",n);
			break;
		}
		else i++;
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 600
n = int(input())
h = list(map(int, input().split()))
c = [0] * n

c[0] = 0
c[1] = abs(h[1] - h[0])
for i in range(n - 2):
    c[i + 2] = min(abs(h[i + 2] - h[i + 1]) + c[i + 1], abs(h[i + 2] - h[i]) + c[i])
print(c[n - 1])

Measured memory_bytes: 13980
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

ll const INF = 1e18;


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M, R; cin >> N >> M >> R;
    ll r[R];
    rep(i, R){
        cin >> r[i];
        r[i]--;
    }

    sort(r, r+R);
    
    ll d[N][N] = {};
    rep(i, N){
        rep(j, N){
            if(i == j) continue;

            d[i][j] = INF;
        }
    }

    rep(i, M){
        int a, b, c; cin >> a >> b >> c;
        a--; b--;

        d[a][b] = c;
        d[b][a] = c;
    }

    for(int k=0; k<N; k++){
        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    // cout << d[0][1] << endl;

    ll ans = 1e18;
    do{
        ll tmp = 0;
        reps(i, 1, R){
            tmp += d[r[i-1]][r[i]];
        }
        ans = min(ans, tmp);
    }while(next_permutation(r, r+R));

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 640
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

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

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int main() {
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    int a = 0;
    int b = 0;

    for(char c : s) {
        if(c == 'A') a++;
        else b++;
    }

    if(a == 2 && b == 1) cout << "Yes\n";
    else if(b == 2 && a == 1) cout << "Yes\n";
    else cout << "No\n";
}


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

using namespace std;
typedef long long ll;

int main() {
  ll n, ans = 0, x;
  cin >> n;
  unordered_map<ll, ll> mp;
  for (ll i = 1; i <= n; ++i) scanf("%lld", &x), ans += mp[i - x], mp[i + x]++;
  printf("%lld", ans);
  return 0;
}


Measured memory_bytes: 18720
#include <bits/stdc++.h>
using namespace std ;
long long h , w ;
bool flag = false ;
int main() {
	long long a , b ,c ;
	cin >> a >> b >> c ;
	if(a + b >= c) {
		cout << "No" << endl ; return 0 ;
	}
	if((c - a - b) * (c - a - b) > 4 * a * b) cout << "Yes" << endl ;
	else cout << "No" << endl ; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c,d;
int i[100000];
int u[100000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >>a>>b;
  if(a>b) swap(a,b);
  for(int n=0;n<b;n++) cout <<a;
  cout <<'\n';
  return (0);
}


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

void push(int);
int pop();
void initialize();
int isEmpty();
int isFull();

int S[MAX];
int top;

int main() {
  int i=0,j,num=0, work1, work2;
  char input[10];

  while(scanf("%s", input) != EOF){
      switch (input[0]) {
      case '+' :
	work1 = pop();
	work2 = pop();
	push(work2+work1);
	break;
      case '-' :
	work1 = pop();
	work2 = pop();
	push(work2-work1);
	break;
      case '/' :
	work1 = pop();
	work2 = pop();
	push(work2/work1);
	break;
      case '*' :
	work1 = pop();
	work2 = pop();
	push(work2*work1);
	break;
      default :
	push(atoi(input));
	break;
      }
  }
  
  printf("%d\n", pop());
  
  return 0;
}



void initialize()
{
  top=0;
}

int isEmpty()
{
  if(sizeof(S) == 0)
    return 1;
  else 
    return 0;
}

int isFull()
{
  if(top >= MAX-1)
    return 1;
  else 
    return 0;
}
 
void push(int x)
{
  if(isFull() == 1){
    printf("over flow\n");
  }

  else{
    top++;
    S[top] = x;
  }
}

int pop()
{
  if(isEmpty() == 1){
    printf("under flow");
  }

  else{
    top--;
    return S[top+1];
  }
}

Measured memory_bytes: 548
#include<iostream>

using namespace std;

int main()
{
  int a,b,c,x;
  int answer = 0;
  cin >> a >> b >> c >> x;
  
  for(int i=0;i <= a;i++){
    int a_total = i*500;
    for(int n=0;n <= b;n++){
      int b_total = n*100;
        for(int j=0;j <= c;j++){
          int c_total = j*50;
          if((a_total + b_total + c_total == x))answer++;
        }
    }
  }
  cout << answer << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 2e6+10;
string s;

void solve()
{
	if(s.back() == 's') cout<<s+"es"<<'\n';
	else cout<<s+"s"<<'\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> s;
	solve();
	return 0;
}

Measured memory_bytes: 3640
A, B, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = min(A) + min(B)

for _ in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    ans = min(ans, A[x]+B[y]-c)

print(ans)


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int a[] = {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    int n;
    cin >> n;
    cout << a[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
def f(a, b):
    A = 1
    B = 1

    while True:
        if a // 10 > 0:
            A += 1
            a = a // 10
        else:
            break

    while True:
        if b // 10 > 0:
            B += 1
            b = b // 10
        else:
            break

    return max(A, B)
# ============================

N = int(input())

ans = 10 ** 10
for i in range(1, int(N ** (1/2) + 1)):
    if N % i == 0:
        A = i
        B = N // i
        ans = min(ans, f(A, B))
    else:
        pass

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define STACK_SIZE 100

int pop(int *stack, int *tail) 
{
    return stack[(*tail)--]; 
}

void push(int push_operand, int *stack, int *tail)
{
    stack[++(*tail)] = push_operand; 
}

int digitsNum(int num)
{
    int digit = 0, tmp = num;

    while(tmp != 0) {
        tmp = tmp / 10;
        ++digit;
    }

    return digit;
}

void calc(char *operand, int *stack, int *tail) 
{
    int left_operand, right_operand;

    if(!isdigit(operand[0])) {    
        right_operand = pop(stack, tail);
        left_operand = pop(stack, tail);
        if(strcmp(operand, "+") == 0) {
            push(left_operand + right_operand, stack, tail);
        } else if(strcmp(operand, "-") == 0) {
            push(left_operand - right_operand, stack, tail);
        } else if(strcmp(operand, "*") == 0) {
            push(left_operand * right_operand, stack, tail);
        } 
    }else {
        push(atoi(operand), stack, tail); 
    }
}

int main(void)
{
    int tail = -1, stack[STACK_SIZE];
    char str[400], *operand;

    fgets(str, sizeof(str), stdin);
    strtok(str, "\n\0");
    operand = strtok(str, " ");
    calc(operand, stack, &tail);
    while((operand = strtok(NULL, " ")) != NULL) {
        calc(operand, stack, &tail);
    }
    printf("%d\n", pop(stack, &tail));

    return 0;
}

Measured memory_bytes: 528
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class ASharingCookies {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int a, b;
	    in >> a >> b;
	    if(a%3==0 || b%3==0 || (a+b)%3==0) out << "Possible" << endl;
	    else out << "Impossible" << endl;
	}
};


int main() {
	ASharingCookies solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int res = 0;
  int a[26] = {};
  int b[26] = {};
  REP(i , s.size()-1){
    REP(j,26){
      a[j] = 0;
      b[j] = 0;
    }

      for(int j = 0;j <= i;j++){
	a[s[j]-'a']++;
      }
      rep(j,i+1,s.size()){
	b[s[j]-'a']++;
      }
      int sum = 0;
      REP(j,26){
	if(a[j] > 0 && b[j] > 0){
	  sum++;
	}
      }
      res = max(res,sum);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
n,k=gets.split.map(&:to_i)
arr=Array.new(100001){0}
n.times do
  a,b=gets.split.map(&:to_i)
  arr[a]+=b
end

(1..100000).each do |i|
  if k <= arr[i]
    puts i
    break
  end
  k-=arr[i]
end

Measured memory_bytes: 2556
#include <stdio.h>
#include <stdlib.h>
int main(){
  int N,*A,i,j,minj,c=0,a=0;

  scanf("%d",&N);

  A=(int*)malloc(N*sizeof(int));

 
  for(i=0;i<N;i++)scanf("%d",&A[i]);

  
  for(i=0;i<N;i++){

    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj]) minj=j;
        }


    a=A[i];
  
    A[i]=A[minj];
    A[minj]=a;
    if(i!=minj) c++;
  }
  printf("%d",A[0]);
  for(i=1;i<N;i++)printf(" %d",A[i]);
  printf("\n%d\n",c);
  close(A);
  return 0;
  
}

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

using namespace std;

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

    vector<long> a(n+1), b(n);
    for(auto &x: a) cin >> x;
    for(auto &x: b) cin >> x;

    long r = 0;
    for(int i=0; i<n; i++) {
        long t = min(a[i], b[i]);
        r += t;
        a[i] -= t;
        b[i] -= t;

        long s = min(a[i+1], b[i]);
        r += s;
        a[i+1] -= s;
        b[i] -= s;
    }
    cout << r << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()
 
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}
 
typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;
const int MOD = 1e9+7;


int main() {
      int n;cin >> n;
      int a,b,c,d;
      cin >> a >> b >> c >> d;
      string s;cin >> s;
      if(c<b){
            for(int i=a-1;i<d-2;i++){
                  if(i>=c-1 && i<=b-1)continue;
                  if(s[i] == '#' && s[i+1] == '#'){
                        cout << "No";
                        return 0;
                  }
            }
            cout << "Yes";
            return 0;
      }else if(c<d){
             for(int i=a-1;i<d-2;i++){
                  if(s[i] == '#' && s[i+1] == '#'){
                        cout << "No";
                        return 0;
                  }
            }
            cout << "Yes";
            return 0;
      }else if(d<c){
             for(int i=a-1;i<c-2;i++){
                  if(s[i] == '#' && s[i+1] == '#'){
                        cout << "No";
                        return 0;
                  }
            }
            for(int i=b-2;i<=d-2;i++){
                  if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.'){
                        cout << "Yes";
                        return 0;
                  }
            }
            cout << "No";
      }
      return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			int sum = 0;
			while(n>0){
				n/=5;
				sum+=n;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 0
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>

#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define speedhack ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


using namespace std;
const ll MAXN = 2e9+2;
const ll SIZE = 1e5+2;
const ll mod = 1e9+7;
bool used[SIZE];

int main(){ speedhack;
	int n,k;
	cin >> n >> k;
	char prev;
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		char c; cin >> c;
		if(c == prev)
		cnt++;
		prev = c;
	}
	if(cnt+(k*2) >= n){
		cout << n-1 << endl;
	}else{
		cout << cnt+k*2 << endl;
	}
	return 0;
}







Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    (0..$i).map(|_| $e.get::<$t>()).collect::<Vec<$t>>()
  };
  ($e:expr => $row:expr, $col:expr; $t:ty) => {
    (0..$i).map(|_| scan!($e => $col; $t)).collect::<Vec<$t>>()
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

trait Writable {
  fn write(&self, sep: &'static str) -> String;
}

impl<T: ToString> Writable for Vec<T> {
  fn write(&self, sep: &'static str) -> String {
    self.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep)
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let (n, k) = scan!(sc; i32, i32);
  println!("{}", n - k + 1);
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << 180 * (n - 2) << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
char moji[200];
int kaisu[100];

int main(void)
{
	while(1){
		int n,i,j=0;
		scanf("%s",moji);
		if(moji[0]=='-') break;
		scanf(" %d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&kaisu[i]);
		}
		for(i=0;i<n;i++){
			strncat(moji,moji,kaisu[i]);
			fun(i);
		}
		printf("%s\n",moji);
	}
	return 0;
}

int fun(int i){
	int j=0;
	while(moji[j]!='\0'){
		moji[j]=moji[j+kaisu[i]];
		j++;
	}
	
	return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 20 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll A[MAX][MAX];

ll solve(ll N, ll M, ll X, const vector<ll>& cs)
{
    ll ans = oo;

    for (int mask = 1; mask < (1 << N); ++mask)
    {
        ll res = 0;
        vector<ll> ys(M, 0);

        for (int i = 0; i < N; ++i)
        {
            if (mask & (1 << i))
            {
                res += cs[i];

                for (int j = 0; j < M; ++j)
                    ys[j] += A[i][j];
            }
        }

        bool ok = true;

        for (int j = 0; j < M; ++j)
        {
            if (ys[j] < X)
            {
                ok = false;
                break;
            }
        }

        if (ok)
            ans = min(ans, res);
    }

    return ans == oo ? -1 : ans;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N, M, X;
    cin >> N >> M >> X;

    vector<ll> cs(N);

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

        for (int j = 0; j < M; ++j)
            cin >> A[i][j];
    }

    auto ans = solve(N, M, X, cs);

    cout << ans << '\n';

    return 0;
}


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

#define int long long
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; }

signed main(){
	int n;
	cin >> n;

	int a[200010];
	deque<int> deq;
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}

	sort(a, a+n, greater<int>());

	for(int i = 0;i < n;i++){
		deq.push_back(a[i]);
	}

	int ans = 0;
	vector<int> now;
	now.push_back(a[0]);
	deq.pop_front();

	for(int i = 1;i < n;i+=2){
		ans += now[i-1];
		int x1 = deq.front();
		deq.pop_front();
		if(i+1 < n){
			ans += x1;
			now.push_back(deq.back());
		}
		now.push_back(x1);
	}

	cout << ans << endl;

	return 0;
}


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

#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int a=0;
    int n=s.length();
    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            a++;
        }
        else{
            a--;
        }
    }
    cout <<n-abs(a)<<endl;
    return 0;
}


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

/*                     
*/

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define len(s) s.length()
#define forp(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define ren(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (int i = a; i >= b; i--)
#define on cout << endl
#define o2(a, b) cout << a << " " << b
#define os cout << " "
#define all(v) v.begin(), v.end()
#define mem(n, m) memset(n, m, sizeof(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sii set<int>
#define us unordered_set<int>
#define um unordered_map<int, int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ret return 0
#define present(s, x) (s.find(x) != s.end())
#define cpresent(s, x) (find(all(s), x) != s.end())
#define ford(container, it) for (__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fors(container, it, a, b) for (__typeof(container.begin()) it = a; it != b; it++)

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100001
#define SIZ 1000001
#define SIZE 200001

typedef long long ll;
typedef long double ldo;
typedef double db;
using namespace std;
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

//Everything is temporary...So,enjoy little things...
void c_p_c()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    c_p_c();
    string s, t;
    cin >> s >> t;
    int j = 0;
    int ans = INT_MAX;

    for (int i = 0; i <= (int)len(s) - (int)len(t); i++)
    {
        int cnt = 0;
        int l = i;
        int j;
        for (j = 0; j < len(t); j++)
        {
            if (t[j] != s[l])
            {
                cnt++;
            }
            l++;
            
        }
        if (j == (int)len(t))
        {
            ans = min(ans, cnt);
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
long long n,T;
long long base[70];
long long a[210];
string b;
int main(){
	cin>>T;
	while(T--){
		cin>>n;
		for(long long i=1;i<=n;++i){
			cin>>a[i];
		}
		cin>>b;
		memset(base,0,sizeof(base));
		bool y=1;
		for(long long i=n;i>=1&&y;--i){
			if(b[i-1]=='0'){
				long long x=a[i];
				for(long long j=0;j<64;++j){
					if((x>>j)&1){
						if(!base[j]){
							base[j]=x;
							break;
						}
						else{
							x^=base[j];
						}
					}
				}	
			}
			else{
				long long x=a[i];
				for(long long j=0;j<64;++j){
					if((x>>j)&1){
						if(base[j]){
							x^=base[j];
						}
						else break;
					}
				}
				if(x){
					y=0;
				}
			}
		}
		cout<<(!y)<<'\n';
	}
	return 0;
}

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

int main(){
  int i,j,cnt=0;
  int n,m,k;
  cin>>n>>m>>k;
  for(i=0;i<=n;i++){
    for(j=0;j<=m;j++){
      if(i*(m-j)+j*(n-i)==k){
        cout<<"Yes";
        return 0;
      }
    }
  }
  cout<<"No";
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int firstIndex = S.length();
		int lastIndex = S.length();
		char[] sArray = S.toCharArray();
		for (int i = 0; i < sArray.length; i++) {
			if (firstIndex == S.length() && sArray[i] == 'A')
				firstIndex = i;
			if (sArray[i] == 'Z')
				lastIndex = i;
		}
		System.out.println(S.substring(firstIndex, lastIndex + 1).length());
		sc.close();
	}
}

Measured memory_bytes: 25904