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

using namespace std;
int main(){
  long long N,K;
  int flag = 1;
  cin >> N >> K;
  long long n = N % K;
	
  while(flag){
  	if (n < abs(n -K))
   {
     flag = 0;
   }
   else
   {
     n = abs(n-K);
   }
  }
  
  cout << n << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define neko 100010
#define heko 410
#define qwq return printf("YES"),0; 
#define orz return printf("NO"),0; 
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
static int n,H;
typedef int arr[heko];
arr fa,book,dgi,dgo,out;
namespace IO
{
	const unsigned int bufsize=1<<16,outsize=1<<24;
	static char ch[bufsize],*S=ch,*T=ch;
	inline char getc()
	{return ((S==T)&&(T=(S=ch)+fread(ch,1,bufsize,stdin),S==T)?0:*S++);}
	static char Out[outsize],*nowp=Out;
	inline void flush(){fwrite(Out,1,nowp-Out,stdout);nowp=Out;}
	template<typename T>
		void read(T &x)
		{
			char c=getc();x=0;
			for(;!isdigit(c);c=getc());
			for(;isdigit(c);x=(x<<1)+(x<<3)+(c^'0'),c=getc());
		}
	template<typename T>
		void write(T x,char c='\n')
		{
			if(!x)*nowp++='0';
			static unsigned int stk[50],tp=0;
			for(;x;x/=10)stk[++tp]=x%10;
			for(;tp;*nowp++=stk[tp--]^'0');*nowp++=c;
		}
}
int find(int x){return fa[x]^x?fa[x]=find(fa[x]):x;}
int main()
{
	using namespace IO;
	int x,y,z,o,X,Y;
	read(n),read(H);
	f(i,0,H<<1)fa[i]=i;
	f(i,1,n)
	{
		read(x),read(y),read(z),read(o);
		if(z==0)X=H+x;
		else X=H-z;
		if(o==0)Y=H-y;
		else Y=H+o;
		book[X]=book[Y]=1;
		++dgi[Y],++dgo[X];
		fa[find(Y)]=find(X);

	}
	f(i,0,H)if(dgi[i]<dgo[i])orz;
	f(i,H+1,H<<1)if(dgi[i]>dgo[i])orz;
	f(i,0,H<<1)if(dgi[i]^dgo[i])out[fa[i]]=1;
	f(i,0,H<<1)if(fa[i]==i&&book[i]&&!out[fa[i]])orz;
	qwq;
}

Measured memory_bytes: 256
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        char[] S = next().toCharArray();
        char[] T = next().toCharArray();

        int count = 0;
        for(int i=0; i<S.length; i++){
            if(S[i] == T[i]){
                count++;
            }
        }

        println(count);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder0525
{
    class Class1
    {
        static void Main(string[] args)
        {

            string line = Console.ReadLine();
            string[] arr = line.Split(' ');
            long r = long.Parse(arr[0]);
            long D = long.Parse(arr[1]);
            long x2000 = long.Parse(arr[2]);

            long x = x2000;
            for (int i = 2001; i <= 2010; i++)
            {
                x = r * x - D;
                Console.WriteLine(x);
            }
        }
    }
}


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

using namespace std;



int main() {

    int n,x,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x;
        if(i%2==1 && x%2==1)cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
int main(){
  string s;
  cin >> s;
  int q;
  cin >> q;
  string t;
  rep(qi,q) {
    int ty;
    cin >> ty;
    if (ty == 1) {
      swap(s,t);
    } 
    else {
      int f; 
      char c;
      cin >> f >> c;
      if(f == 1){
        t += c;
      } 
      else{
        s += c;
      }
    }
  }
  reverse(t.begin(), t.end());
  t += s;
  cout << t << endl;
}





Measured memory_bytes: 1128
def usage():
    c, n = map(int, input().split())
    if c == 1:
        print(n)
        return 0
    ans = 1
    fct = factorize(n)
    for i in range(len(fct)):
        if fct[i][1] >= c:
            ans *= fct[i][0] ** (fct[i][1] // c)
    print(ans)


def factorize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


if __name__ == '__main__':
    usage()


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
    int ans=0, color, i=0;
    char s[10*10*10*10*10*10];
    scanf("%s", s);

    while(s[i] != '\0'){
        if((s[i]=='W' && s[i+1]=='B') ||(s[i]=='B' &&s[i+1]=='W')){
                ans++;
            }
        i++;
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
multiset<int> s;

int main() {
    int n;
    cin >> n;
    s.clear();
    for (int i = 1; i <= n; i++) {
        int tmp;
        scanf("%d", &tmp);
        auto id = s.lower_bound(tmp);
        if (id != s.begin()) s.erase(--id);
        s.insert(tmp);
    }
    cout << s.size();

}

Measured memory_bytes: 8252
#include<iostream>
#include<cstdio>
#include<math.h>

using namespace std;

int main() {
	int n, y, b=1, s=1;
	cin >> n;
	string C[36], B[36], S[36];
	for (int i = 0; i < n; i++) {cin >> C[i]; B[i] = C[i]; S[i] = C[i];}
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j > i; j--) {
			if (B[j][1] < B[j - 1][1]) {
				string x = B[j]; B[j] = B[j - 1]; B[j - 1] = x;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		y = 0;
		if (i <= n - 2 && b == 1) {
			int z = 0;
			if (B[i][1] != B[i + 1][1]) y = 0;
			else if (i == 0) y = 1;
			else if (B[i - 1][1] == B[i][1]) {
				if (i >= 2 && B[i - 2][1] == B[i][1]) y = 3;
				else y = 2;
			}
			else y = 1;
		}
		if (y != 0) {
			int z = 0;
			for (int j = 0; j < n; j++) {
				if (C[j][1] == B[i][1]) {
					z++;
					if (z == y) { if (C[j][0] != B[i][0]) b = 0; break; }
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << B[i];
		if (i == n - 1) cout << endl;
		else cout << " ";
	}
	if (b == 1) cout << "Stable" << endl;
	else cout << "Not stable" << endl;

	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (S[j][1] < S[minj][1]) minj = j;
		}
		string x = S[i]; S[i] = S[minj]; S[minj] = x;
	}
	for (int i = 0; i < n; i++) {
		y = 0;
		if (i <= n - 2 && s == 1) {
			int z = 0;
			if (S[i][1] != S[i + 1][1]) y = 0;
			else if (i == 0) y = 1;
			else if (S[i - 1][1] == S[i][1]) {
				if (i >= 2 && S[i - 2][1] == S[i][1]) y = 3;
				else y = 2;
			}
			else y = 1;
		}
		if (y != 0) {
			int z = 0;
			for (int j = 0; j < n; j++) {
				if (C[j][1] == S[i][1]) {
					z++;
					if (z == y) { if (C[j][0] != S[i][0]) s = 0; break; }
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << S[i];
		if (i == n - 1) cout << endl;
		else cout << " ";
	}
	if (s == 1) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	return 0;
}


Measured memory_bytes: 3232
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int p,q,r;
    cin>>p>>q>>r;
    cout<<min({p+q,q+r,r+p})<<endl;
}

Measured memory_bytes: 256
/**
 * Created by rasrivastava on 10/23/16.
 */
class RangeProduct(val a : Int,val b : Int) {
  def getPositives(range: Range) : Int = {
    if (range.min < 0 && range.max < 0) {
      0
    }else {
      range.length
    }
  }

  def getNegatives(range: Range) : Int = {
    if (range.min > 0 && range.max > 0) {
      0
    }else {
      range.length
    }
  }


  def getSign() : String = {
    val range = a to b
    if (range.contains(0)) {
      "Zero"
    }else {
      val positives = getPositives(range)
      val negatives = getNegatives(range)
      if (positives > 0) {
        "Positive"
      }else {
        if (negatives > 0) {
          if (negatives % 2 == 0) {
            "Positive"
          }else {
            "Negative"
          }
        }else {
          "Zero"
        }
      }
    }
  }
}


object Main extends App {
  val line = readLine()
  val lineArr = line.split(" ")
  println(new RangeProduct(lineArr(0).toInt,lineArr(1).toInt).getSign())
}

Measured memory_bytes: 21540
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll n;
cin>>n;
string s;
cin>>s;
for(int i=0;i<s.size();i++){
    cout<<(char)('A'+(s[i]-'A'+n)%26);
}
}










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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> bool chmax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

int dp[3001];

int main() {
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    sort(all(a));
    fill(dp, dp + t + 1, -1);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = t - 1; j >= 0; --j) {
            if (dp[j] >= 0) {
                chmax(dp[min(t, j + a[i].first)], dp[j] + a[i].second);
            }
        }
    }
    cout << *max_element(dp, dp + t + 1) << endl;

    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<iomanip>

using namespace std;


int main(){
  int n,k,i,buf,j=1,t2=1;
  double r=0;

  cin>>n>>k;
  for(i=0;i<n;i++){
    buf=(n-i)*t2;
    while(buf<k){
      buf=buf*2;
      t2=t2*2;
    }

    r+=1/(double)t2;
  }

  cout<<fixed<<setprecision(13)<<r/n<<endl;

  return 0;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    s = list(input()[:-1].decode())
    s[k - 1] = s[k - 1].lower()
    print(*s, sep='')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

bool used[51];
vector<pii> G[51];

void dfs(int v, int ige)
{
	used[v] = true;
	for (auto e : G[v])
	{
		if (e.second == ige)continue;
		if (used[e.first])continue;
		dfs(e.first, ige);
	}
}

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

	int N, M;

	cin >> N >> M;
	int s, t;
	rep(i, 0, M)
	{
		cin >> s >> t;
		s--, t--;
		G[s].push_back(mp(t, i));
		G[t].push_back(mp(s, i));
	}

	int ans = 0;
	rep(i, 0, M)
	{
		fill(used, used + N, false);
		dfs(0, i);
		bool ok = true;
		rep(j, 0, N)
		{
			if (!used[j])
			{
				ok = false;
				break;
			}
		}
		if (!ok)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(){
int k,t,a[100];
cin>>k>>t;
for (int i = 0; i < 100; ++i)
{
	a[i]=0;
}
for (int i = 0; i<100; ++i)
{
	cin>>a[i];
}
int max;
max = a[0];
    for (int i = 0; i < 100; i++) {
        if (max < a[i]) {
            max = a[i];
        }
    }
if ((k+1)/2 >= max) cout<<0<<endl;
else if ((k+1)/2 <= max){
	cout<< (max - (k+1)/2)*2-1 <<endl;
}

return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int w, h;
char data[50][50];
int cnt;
char bw;
bool flag;
 
void rec(int x, int y) {
  static int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
  data[y][x] = '#';
  cnt++;
  for(int i = 0; i < 4; i++) {
    int nx = x + d[i][0];
    int ny = y + d[i][1];
    if(nx < 0 || nx >= w) continue;
    if(ny < 0 || ny >= h) continue;
    if(data[ny][nx] == '#') continue;
    if(data[ny][nx] != '.') {
      if(bw == '.') bw = data[ny][nx];
      else if(data[ny][nx] != bw) flag = false;
      continue;
    }
    rec(nx, ny);
  }
}
 
int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        cin >> data[i][j];
      }
    }
    int numW = 0;
    int numB = 0;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        if(data[i][j] == '.') {
          cnt = 0;
          bw = '.';
          flag = true;
          rec(j, i);
          if(flag) {
            if(bw == 'B') numB += cnt;
            else if(bw == 'W') numW += cnt;
          }
        }
      }
    }
    cout << numB << ' ' << numW << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next());
        Integer m = Integer.parseInt(sc.next());
        Integer[] l = new Integer[m];
        Integer[] r = new Integer[m];
        for (int i = 0; i < m; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        Arrays.sort(l);
        Arrays.sort(r);

        int min = l[m - 1];
        int max = r[0];

        int result = max - min + 1 < 0 ? 0 : Math.min(max - min + 1, n);

        // 出力
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 63320
#include<bits/stdc++.h>
#define mod 1000000007
#define mod1 998244353
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
int main()
{
fast_io
li a,b;
cin>>a>>b;
if(a>1&&b>1)
cout<<(a*b)/2+(a*b)%2;
else
cout<<"1";
return  0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>

#define REP(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define RREP(i,x,y) for(int i=(int)(x);i>=(int)(y);i--)
#define all(x) (x).begin(),(x).end()

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long ll;

using namespace std;

const int MAX_N = 2 * 100000;

int n;
int a[MAX_N];

string solve() {
    string ans = "";
    RREP(i, n-1, 0){
        if(i % 2 != 1 ^ n % 2 == 1) continue;
        ans += to_string(a[i]) + " ";
    }
    REP(i, 0, n){
        if(i % 2 != 0 ^ n % 2 == 1) continue;
        ans += to_string(a[i]) + " ";
    }
    ans.substr(0, ans.length() - 1);
    return ans;
}

int main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    REP(i, 0, n) cin >> a[i];
    cout << solve() << "\n";
    return 0;
}


Measured memory_bytes: 4992
N=int(input())
alist=[0]+list(map(int,input().split()))

answer=0
for i in range(1,N):
  if alist[i]==i:
    alist[i],alist[i+1]=alist[i+1],alist[i]
    answer+=1
    
if alist[N]==N:
  print(answer+1)
else:
  print(answer)

Measured memory_bytes: 14008
from collections import defaultdict

N, M = map(int, input().split())
d = defaultdict(list)
penalty = 0
accepted = 0

for p, S in (input().split() for _ in range(M)):
    d[p].append(S)

for k, v in d.items():
    tmp = 0
    for i in v:
        if i=="AC":
            accepted += 1
            penalty += tmp
            break
        else:
            tmp += 1

print(accepted, penalty)

Measured memory_bytes: 31868
// template version 1.0
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
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; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int x1, x2, y1, y2;cin>>x1>>y1>>x2>>y2;

  int y3 = y2 + (x2-x1);
  int x3 = x2 + (y1-y2);
  int y4 = y1 + (x2-x1);
  int x4 = x1 + (y1-y2);

  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;


  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc061/editorial.pdf
・ベルマンフォード
・負の閉路があっても、そこに頂点Nが含まれなければ今回はOK
　って点に気付けなかったー。
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

N, M = map(int, input().split())

edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    # 0-indexed
    # コストの正負を逆転させれば最短経路問題として処理できる
    edges[i] = (a-1, b-1, -c)

def bellman_ford(N: int, edges: list, start: int) -> list:
    # 頂点[ある始点からの最短距離]
    # (経路自体を知りたい時はここに前の頂点も持たせる)
    verts = [float('inf')] * N
    verts[start] = 0
    # 各辺によるコストの置き換えを頂点数N-1回繰り返す
    for i in range(N-1):
        for src, dest, cost in edges:
            if verts[dest] > verts[src] + cost:
                verts[dest] = verts[src] + cost
    # 無限に減らせる場所がないか確認
    for i in range(N):
        for src, dest, cost in edges:
            if verts[dest] > verts[src] + cost:
                verts[dest] = verts[src] + cost
                if dest == N-1:
                    # 頂点Nがそれに該当していたら空リストを返却
                    return []
    # 問題なければ頂点リストを返却
    return verts

verts = bellman_ford(N, edges, 0)
if not verts:
    print('inf')
else:
    # 正負を戻して出力
    print(-verts[N-1])


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int > > > pair4;
#define MAXN 200013
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#define IINF 1000000000
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

ll a, b;

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

	cin >> a >> b;

	ll divisor = __gcd(a, b);

	int unique = 1; //one

	ll temp = divisor;
	for (int i = 2; i < sqrt(divisor) + 10; i++) {
		if (temp % i != 0) continue;

		unique++;
		while (temp % i == 0) {
			temp /= i;
		}
	}

	if (temp != 1) unique++;

	cout << unique << endl;
}

Measured memory_bytes: 384
s=input()
t=input()
ans=[]
for i in range(len(s)-len(t)+1):
  failflag=0
  for j in range(len(t)):
    if s[i+j]!=t[j] and s[i+j]!='?':
      failflag=1
      break
  if failflag==0:
    k=[]
    for j in range(i):
      if s[j]!='?':
        k.append(s[j])
      else:
        k.append('a')
    for j in range(len(t)):
      k.append(t[j])
    for j in range(i+len(t),len(s)):
      if s[j]!='?':
        k.append(s[j])
      else:
        k.append('a')
    ans.append(''.join(k))
if len(ans)==0:
  print('UNRESTORABLE')
else:
  ans.sort()
  print(ans[0])
      

Measured memory_bytes: 64304
using System;

namespace K___Stones
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NK[0];
            var K = NK[1];
            var picks = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            var DP = new bool[K + 1];
            for (int i = 0; i < K + 1; i++) DP[i] = false;

            for (int i = K; i >= 0; i--)
            {
                for (int j = 0; j < N && picks[j] <= K - i; j++)
                {
                    if (!DP[i + picks[j]])
                    {
                        DP[i] = true;
                        break;
                    }
                }
            }

            Console.WriteLine(DP[0]?"First":"Second");
        }
    }
}


Measured memory_bytes: 13164
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;

template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n,k;
int mod=1e9+7;
int table[2005][2005];
int32_t main()
{
    IOS;
    cin>>n>>k;
    table[0][0]=1;
    for(int i=1;i<=2001;i++)
    {
        table[i][0]=1;
        for(int j=1;j<=i;j++)
            table[i][j]=(table[i-1][j]+table[i-1][j-1])%mod;
    }
    for(int i=1;i<=k;i++)
    {
        //method for k blue balls = x1+x2...+xi=k; x1>0 x2>0... xi>0
        //formula =(k-1,i-1)

        //method for n-k red balls = Coeff of x^(n-k) in x^(i-1)*(1+x+x^2...)^(i+1)
        //Coeff of x^(n-k-i+1) in (1-x)^(-(i+1))
        //formula =(i+1+n-k-i+1-1,n-k-i+1) = (n-k+1,n-k-i+1)

        if(k-1<i-1 || n-k+1<n-k-i+1)
            print(0);
        else
        {
            int ans=table[k-1][i-1];
            ans*=table[n-k+1][n-k-i+1];
            ans%=mod;
            print(ans);
        }
    }
}

Measured memory_bytes: 26252
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll n,m;
ll ans;
ll a,b;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>m;
	a=n%m;
	b=m-a;
	cout<<min(a,b);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n, sum=0, a, b;
    cin >> n;
    a = n/500;
    sum = sum + (a*1000);
    n = n%500;

    a = n/5;
    sum += (a*5);

    cout << sum << endl;

}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	public void run() throws Exception {
		Scanner sc = new Scanner();
		int[] a = new int[3];
		for (int i = 0; i < 3; ++i)
			a[i] = sc.nextInt();
		Arrays.sort(a);
		System.out.println(a[2] * 10 + a[1] + a[0]);
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		int nextInt() {
			return (int) nextLong();
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 21972
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pob pop_back
#define ft first
#define ftt ft.ft
#define ftc ft.sc
#define sc second
#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define ctz __builtin_ctz
typedef pair<int, int> pii;
typedef pair<ll ,ll> pll;
const int maxn = 1e3;
 


int n ,k ,day ,x ,a[maxn + 21] ,res;

int f(int k){
    int res = 0;
       for(int i = 1; i <= day; i += k)
           res++;
       return res;   

}
int main(){FAST;
    cin >> n >> day >> x;
    forp(i ,0 ,n)
        cin >> k, res +=f(k);
    out(res + x);
   return 0;
}
 












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

int main()
{
  string s;

  cin >> s;
  for (int i=0; i<4; i++){
    cout << s[i];
  }
  cout << " ";
  for (int i=4; i<s.size(); i++){
    cout << s[i];
  }
  cout << endl;
  
  return 0;
}
  


Measured memory_bytes: 256
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <ios>
#include <cmath>
#include <algorithm>
 
using namespace std;


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0;
    for(int i = 0; i < n; i++){
        r += s.at(i) == 'R';
    }
    int counter = 0;
    for(int i = 0; i < r; i++){
        counter += s.at(i) == 'W';
    }
    cout << counter;
}


Measured memory_bytes: 3488
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x, y;
	if (a < b) x = a; else x = b;
	if (c < d) y = c; else y = d;
	cout << x + y;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int h, w;
    cin >> h >> w;
    char ext[2 * h][w];
    memset(ext, '.', sizeof ext);
    int last = 0;
    forn(i, h) {
        string s;
        cin >> s;
        forn(j, w) {
            ext[i + last][j] = s[j];
            ext[i + last + 1][j] = s[j];
                }
        last++;
    }
    forn(i, 2 * h) {
        forn(j, w) {
            cout << ext[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N, K;
    cin >> N >> K;

    vector<pair<ll, ll> > v;
    ll a, b;
    rep(i, N){
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    sort(v.begin(), v.end());
    
    ll p = 0;
    ll vp = -1;
    while(p < K){
        vp++;
        p += v[vp].second;//cout << "p: " << p << ", vp: " << vp << endl;
    }

    cout << v[vp].first << endl;

    return 0;
}

Measured memory_bytes: 5284
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int X;
    cin >> X ;
    int fh = (X/500) * 1000;
    X = X % 500;
    fh += (X/5) * 5;
    cout << fh << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
      int S = sc.nextInt();
      int h = S / 3600;
      int amari1 = S % 3600;
      int m = amari1 / 60;
      int s = amari1 % 60;
      System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26132
#include<iostream>
using namespace std;
int main()
{
  char x, y;
  char A = 10, B = 11, C = 12, D = 13, E = 14, F = 15;
  cin >> x >> y;
  if(x == y)
    cout << "=";
  if(x > y)
    cout << ">";
  if(x < y)
    cout << "<";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<sstream>
#include<string>
using namespace std;
#define rep(i,ii,n) for(int i=ii;i<n;i++)
#define inf INT_MAX
#define mod (1000000007LL)
#define ll long long 
#define ull unsigned long long 
#define all v.begin(),v.end()
#define vi vector<int>
#define pb push_back



int main(){ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    string s;
    cin>>s;
    for (int i=0;i<s.length();i++){
        if (s[i]=='?'){
            if(i!=0 && s[i-1]=='P'){
                s[i]='D';
            }
            else if(i!=s.length()-1 && s[i+1]=='D'){
                s[i]='P';
            } 
            else if(i!=s.length()-1 && s[i+1]=='?'){
                s[i]='P';
                s[i+1]='D';
            }

            else s[i]='D';
            
        }
         
            
        
    }
    cout<<s;

 




 return 0;   
}//main



Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int D=365;
  //cin>>D;
  vector<int> c(26);
  vector<vector<int>> s(D,vector<int>(26,0));
  vector<int> t(D,0);
  rep(i,26)
    cin>>c.at(i);
  rep(i,D){
    rep(j,26)
      cin>>s.at(i).at(j);
  }
  
  /*rep(i,D){
    cin>>t.at(i);
    t.at(i)--;
  }*/
  
  vector<in> v(D,0);
  vector<int> last(26,0);
  vector<int> last_alt=last;
  in sum=0;
  
  for(int i=0;i<D;i++){
    rep(T,26){
      in sum_alt;
      if(i==0) sum=0;
      else
        sum_alt=v.at(i-1);
      
      last_alt=last;
      
      last_alt.at(T)=i+1;
      sum_alt+=s.at(i).at(T);
      rep(j,26)
        sum_alt-=c.at(j)*(i+1-last.at(j));
      if(sum<sum_alt){
        t.at(i)=T;
        sum=sum_alt;
      }
    }
    v.at(i)=sum;
  }
  
  /*rep(i,D)
    cout<<v.at(i)<<endl;*/
  rep(i,D)
    cout<<t.at(i)+1<<endl;
  
}

Measured memory_bytes: 3692
module Main where

import Control.Applicative
import Control.Monad

main :: IO ()
main = do
    n <- readLn
    [d, x] <- fmap read . words <$> getLine
    as <- replicateM n readLn
    let eat a = (d + a - 1) `div` a
    let ans = (sum $ fmap eat as) + x
    print ans

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define rep3(i, s, n) for (int i = s; i > (int)n; i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cout << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

const double EPS = 1e-9;
const double pi = 3.141592653589;
double a, b, x;

double vol(double t)  {
	if (tan(t) <= b / a) {
		return a * a * (b - a * tan(t) / 2.0);
	} else {
		return a * b * b / (2.0 * tan(t));
	}
}

bool test(double t) {
	return x <= vol(t);
}

int main() {
	cin >> a >> b >> x;
	cerr << setprecision(12);
	
	double ok = 0.0, ng = pi / 2.0 - EPS;
	assert(test(ok)); assert(!test(ng));
	for (int cnt = 0; cnt < 100 and abs(ok - ng) > EPS; cnt++) {
		double mid = (ok + ng) / 2.0;

		if (test(mid)) ok = mid;
		else ng = mid;
	}

	cout << setprecision(12);
	cout << ok * 180.0 / pi << endl;
}

Measured memory_bytes: 768
#include <iostream>

using namespace std;

void solve()
{
	int a, b;
	cin >> a >> b;
	if (a < b)
	{
		cout << "a < b" << endl;
	}
	else if (a > b)
	{
		cout << "a > b" << endl;
	}
	else
	{
		cout << "a == b" << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int main(){
    long long int N,A,B;
    cin>>N>>A>>B;
    long long int zentai,bubun1,ans,bubun2;
    zentai=N/(A+B);
    bubun1=zentai*A;
    long long int kazu,kazu1;
    kazu=0;
    kazu=min(A,N%(A+B));
    ans=bubun1+kazu;
    cout<<ans<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N, A, B; string S; cin >> N >> A >> B >> S;
  int cnt = 0, bcnt = 0;
  for (int i = 0; i < N; ++i) {
    // printf("%d: %c, %d, %d\n", i, S[i], cnt, bcnt);

    if (S[i] == 'a') {
      if (cnt < A+B) {
        cnt++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else if (S[i] == 'b') {
      if (cnt < A+B && bcnt < B) {
        cnt++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
      bcnt++;
    } else {
      cout << "No" << endl;
    }
  }
}

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

typedef long long ll;

#define reg register 
#define rep(a,b,c) for(reg int a=b,a##end=c;a<=a##end;++a)
#define drep(a,b,c) for(reg int a=b,a##end=c;a>=a##end;--a)

char IO;
int rd(){
	int s=0,f=0;
	while(IO=getchar(),IO<'0'||IO>'9')if(IO=='-')f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(IO=getchar(),IO>='0'&&IO<='9');
	return f?-s:s;
}

const int N=110;

int n,m;
int cnt;

bitset <N> G[N],tmp;

bool vis[N];
int ck;

void dfs(int u){
	if(vis[u]) return;
	else vis[u]=1;
	ck++;
	rep(i,1,n) if(G[u][i]) dfs(i);
}


bool Check(){
	memset(vis,0,sizeof vis);ck=0;
	dfs(1);
	return ck==n;
}



int main(){
	n=rd(),m=rd();cnt=n*(n-1)/2;
	rep(i,1,n) rep(j,i+1,n) G[i][j]=G[j][i]=1;
	if(m)rep(i,1,n) {
		rep(j,i+1,n) if(G[i][j]){
			tmp=G[i]&G[j];
			rep(o,1,n) if(tmp[o]) {
				if(!G[i][j]||!G[i][o]||!G[j][o]) continue;
				G[i][j]=0,G[j][i]=0;
				if(Check()){ cnt--;if(--m==0)break;}
				else {
					G[i][j]=1;G[j][i]=1;
					G[i][o]=0,G[o][i]=0;
					if(Check()){ cnt--;if(--m==0) break;}
					else {
						G[i][o]=1;G[o][i]=1;
						G[j][o]=0,G[o][j]=0;
						if(Check()) {cnt--;if(--m==0) break;}  
						else G[j][o]=1,G[o][j]=1;
					}
				}
			}
			if(m==0) break;
		}
		if(m==0)break;
	}
	if(m==0){
		printf("%d\n",cnt);
		rep(i,1,n) rep(j,i+1,n) if(G[i][j]) printf("%d %d\n",i,j);
	}else {
		puts("-1");
	}
}







Measured memory_bytes: 384
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = INPUT()

    l = 0
    r = 0
    for s in S:
        if s == "(":
            r += 1
        else:
            if r >= 1: 
                r -= 1
            else: 
                l += 1

    print("("*l + S + ")"*r)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38768
from collections import defaultdict, deque
n, m = list(map(int, input().split()))
graph = defaultdict(list)
for i in range(m):
  u, v = list(map(int, input().split()))
  graph[u].append(v+n)
  graph[u+n].append(v+2*n)
  graph[u+2*n].append(v)
s, t = list(map(int, input().split()))
dist = [-1 for i in range(3*n+10)]

def bfs():
  que = deque([s])
  dist[s] = 0
  while len(que) > 0:
    cur = que.popleft()
    if cur==t:
      return dist[cur]//3
    for to in graph[cur]:
      if dist[to] == -1:
        dist[to] = dist[cur]+1
        que.append(to)
  return -1

print(bfs())

Measured memory_bytes: 81224
N = int(input())
Sort = [str(x) for x in range(1,N+1)]
P = [str(x) for x in input().split()]

Count = 0
for T in range(0,N):
    if Sort[T] != P[T]:
        Count += 1
if Count==0 or Count==2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9188
fn main() {
    let n: i32 = read_line_as_value();
    let mut ans: bool = false;
    for i in 1..10 {
        if n % i == 0 {
            let m = n / i;
            if m < 10 {
                ans = true;
            }
        }
    }
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read_line_as_value<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    let res = std::io::stdin().read_line(&mut input);
    if let Err(error) = res {
        panic!("io error at stdin.read_line: {}", error);
    };
    match input.trim().parse() {
        Ok(val) => val,
        _ => panic!("error while parsing input: {}", input)
    }
}

Measured memory_bytes: 2168
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>

class Dice{
public:
    int face[6], facetmp[6];

    Dice(void){
        for (int i = 0; i < 6; i++){
            face[i] = 0;
            facetmp[i] = 0;
        }
    }

    void move(char ch){
        for (int i = 0; i < 6; i++) {
            facetmp[i] = face[i];
        }

        if (ch == 'E') {
            facetmp[0] = face[3];
            facetmp[2] = face[0];
            facetmp[3] = face[5];
            facetmp[5] = face[2];
        }

        else if (ch == 'W') {
            facetmp[0] = face[2];
            facetmp[2] = face[5];
            facetmp[3] = face[0];
            facetmp[5] = face[3];
        }

        else if (ch == 'N') {
            facetmp[0] = face[1];
            facetmp[1] = face[5];
            facetmp[4] = face[0];
            facetmp[5] = face[4];
        }

        else if (ch == 'S') {
            facetmp[0] = face[4];
            facetmp[1] = face[0];
            facetmp[4] = face[5];
            facetmp[5] = face[1];
        }

        else if (ch == 'Z'){
            facetmp[1] = face[3];
            facetmp[2] = face[1];
            facetmp[3] = face[4];
            facetmp[4] = face[2];
        }

        for (int i = 0; i < 6; i++){
            face[i] = facetmp[i];
        }

    }

    void print(){
        cout << face[0] << endl;
    }

};

int main() {
    Dice d1;
    int num[6], q, f1, f2;
    string order = "";
    for (int i = 0; i < 6; i++){
        cin >> num[i];
        d1.face[i] = num[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++){
        cin >> f1 >> f2;

        for (int j = 0; j <= 3; j++){
            for (int k = 0; k <= 3; k++){
                for (int n = 0; n <= 3; n++){
                    order.clear();
                    order.append(j,'E');
                    order.append(k,'S');
                    order.append(n,'Z');

                    for (int l = 0; l < 6; l++){
                        d1.face[l] = num[l];
                    }
                    for (int m = 0; m < order.size(); m++){
                        d1.move(order[m]);
                    }
                    if (d1.face[0] == f1 && d1.face[1] == f2){
                        cout << d1.face[2] << "\n";
                        j = 3;
                        k = 3;
                        n = 3;
                    }
                }

            }
        }
    }

    return 0;
}

Measured memory_bytes: 3180