akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
 
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 52;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;

 
map < pair < string, int >, int > d;
set < pair < int, pair < string, int > > > q;

int n, c[N];
string s[N];

bool check (string s) {
	for (int i = 0; i < sz(s); ++i)
		if (s[i] != s[sz(s) - i - 1])
			return 0;

	return 1;
}

pair < string, int > get (string lf, string rg) {
	for (int i = 0; i < min(sz(lf), sz(rg)); ++i)
		if (rg[sz(rg) - i - 1] != lf[i])
			return mp("", -1);

	if (sz(lf) == sz(rg))
		return mp("", 0);

	if (sz(lf) > sz(rg))
		return mp(lf.substr(sz(rg), sz(lf) - sz(rg)), 0);

	return mp(rg.substr(0, sz(rg) - sz(lf)), 1);
}

main () {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> s[i] >> c[i];
		for (int j = 0; j < 2; ++j)		
			if (!d.count(mp(s[i], j)) || d[mp(s[i], j)] > c[i]) {
				d[mp(s[i], j)] = c[i]; 
				q.insert(mp(c[i], mp(s[i], j)));
			}
	}

	while (sz(q)) {
		pair < string, int > v = q.begin()->s;
		int cost = q.begin()->f;
		q.erase(q.begin());

		if (check(v.f)) {
			cout << cost << endl;
			return 0;
		}

		for (int i = 1; i <= n; ++i) {
			pair < string, int > to;
			if (!v.s)
				to = get(v.f, s[i]);
			else
				to = get(s[i], v.f);

			if (to.s == -1)
				continue;

			if (!d.count(to) || d[to] > cost + c[i]) {
			    if (d.count(to))
					q.erase(mp(d[to], to));
				d[to] = cost + c[i];
				q.insert(mp(d[to], to));
			}
		}
	}

	cout << -1 << endl;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 100000000000000

int main(){
  int N,W;
  cin>>N>>W;
  vector<ll> w(N),v(N);
  for(int i=0;i<N;i++){
    cin>>w.at(i)>>v.at(i);
  }
  vector<vector<ll>> value(4);
  for(int i=0;i<N;i++){
    value.at(w.at(i)-w.at(0)).push_back(v.at(i));
  }

  vector<int> k(4);
  for(int i=0;i<4;i++){
    sort(value.at(i).begin(),value.at(i).end());
    reverse(value.at(i).begin(),value.at(i).end());
    k.at(i)=value.at(i).size();
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<k.at(i)-1;j++){
      value.at(i).at(j+1)+=value.at(i).at(j);
    }
  }
  ll ans=0;
  for(ll i1=0;i1<=k.at(0);i1++){
    for(ll i2=0;i2<=k.at(1);i2++){
      for(ll i3=0;i3<=k.at(2);i3++){
        for(ll i4=0;i4<=k.at(3);i4++){
          if(i1*w.at(0)+i2*(w.at(0)+1)+i3*(w.at(0)+2)+i4*(w.at(0)+3)>W){
            break;
          }
          ll sub=0;
          if(i1>0){
            sub+=value.at(0).at(i1-1);
          }
          if(i2>0){
            sub+=value.at(1).at(i2-1);
          }
          if(i3>0){
            sub+=value.at(2).at(i3-1);
          }
          if(i4>0){
            sub+=value.at(3).at(i4-1);
          }
          ans=max(ans,sub);
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string.h>
using namespace std;

const int INF = 1<<29;
typedef pair<int, int> P;

int n;
P team[2 * (1<<20)];

void init(int _n){
	n = 1;
	while(_n > n)
		n *= 2;
	for(int i = 0; i < 2 * n - 1; ++i){
		team[i] = P(-INF, -INF);
	}
}

void update(int k, int a){
	k += (n - 1);
	team[k] = P(a, k - n + 1);
	
	while(k > 0){
		k = (k - 1) / 2;
		if(team[k * 2 + 1].first == team[k * 2 + 2].first){
			if(team[k * 2 + 1].second < team[k * 2 + 2].second)
				team[k] = team[k * 2 + 1];
			else
				team[k] = team[k * 2 + 2];
		}
		else
			team[k] = max(team[k * 2 + 1], team[k * 2 + 2]);
	}
}

int main() {
	int p[100010] = {0};
    for(int i = 0; i < 100010; ++i)
        p[i] = -INF;
	int m, r, l;
	cin >> m >> r >> l;

	init(m);
    for(int i = 0; i < m; ++i){
		update(i, 0);
        p[i] = 0;
    }
	int d, t, x, prev = 0;
	
	for(int i = 0; i < r; ++i){
		scanf("%d %d %d", &d, &t, &x);
		p[team[0].second] += (t - prev);
		update(d - 1, team[d + n - 2].first + x);
		prev = t;
	}
	p[team[0].second] += (l - prev);

	int ans_max = -INF, ans;
	for(int i = 0; i < m; ++i){
		if(ans_max < p[i]){
            ans = i + 1;
            ans_max = p[i];
        }	
	}
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 18028
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n, p;
	while (cin >> n >> p && (n || p)) {
		vector<int> a(n, 0);
		int i = 0, num = p;
		while (1) {
			if (p != 0) {
				a[i]++;
				p--;
				if (a[i] == num) {
					cout << i << endl;
					break;
				}
			} else if (a[i] != 0) {
				p = a[i];
				a[i] = 0;
			}
			i++;
			if (i >= n) i = 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int X,Y;
    cin >> X >> Y;
    cout << X + Y/2;
}

Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	l, r , d= tin()
	#s = input()
	ret = r // d - (l-1) // d
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 61852
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int,int> pii;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
template <class F, class T> void convert(const F &f, T &t){	stringstream ss; ss << f; ss >> t;}


bool solve(int n){
	vector<int> a(n);
	for(int i=0;i<n;i++) cin>> a[i];
	
	sort(all(a));
	int ans = 0;
	for(int i=1;i<n-1;i++) ans += a[i];
	ans /= n-2;
	
	cout<< ans<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed); cout.precision(10);
	int n;
	while(cin>> n, n){
		solve(n);
	}
	return 0;
}

 

Measured memory_bytes: 1216
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int D, E;
    while (true) {
        cin >> D >> E;
        if (D == 0 && E == 0) { break; }

        double ans = 1e9;
        for (int x = 0; x <= D; x++) {
            int y = D-x;
            ans = min(ans, abs(E-sqrt((double)x*x + y*y)) );
        }
        printf("%.8f\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define endl '\n'
using ll = long long int;
int main() {
    int n, m, k;
    std::string s;
    std::cin >> n >> k >> s;
    char &c = s[k-1];
    c = tolower(c);
    std::cout << s << endl;
}


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

#define YEN_500 500
#define YEN_5 5
#define HAPPINESS_POINTS_LARGE 1000
#define HAPPINESS_POINTS_SMALL 5

int main()
{
	long inputS, fiveHundreadCoinsAmount, fiveCoinsAmount;	

	scanf("%ld", &inputS);

	if (inputS / YEN_500 > 0)
	{
		fiveHundreadCoinsAmount = inputS / 500;
		fiveCoinsAmount = (inputS % YEN_500) / YEN_5;		
		if (fiveCoinsAmount == 0)
		{
			fiveCoinsAmount = 0;
		}
		printf("%ld \n", (fiveHundreadCoinsAmount * HAPPINESS_POINTS_LARGE) + (fiveCoinsAmount * HAPPINESS_POINTS_SMALL));
	}
	else if (inputS / YEN_500 <= 0)
	{		
		fiveCoinsAmount = (inputS % YEN_500) / YEN_5;
		printf("%ld \n",(fiveCoinsAmount * HAPPINESS_POINTS_SMALL));
	}

	return 0;
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    ll a;
    long double b;
    cin >> a >> b;
    
    ll x = floor(a * b);
    cout << x << endl;
	return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3744
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<i64>();
    let mut k = -1;
    for i in 1..n + 1 {
        if i * (i + 1) / 2 == n {
            k = i;
            break;
        }
    }
    if k == -1 {
        println!("No");
        return;
    }
    println!("Yes");
    println!("{}", k+1);
    let mut sv: Vec<Vec<i64>> = vec![];
    let mut ret = vec![];
    let mut i = 1;
    for _ in 0..k + 1 {
        let mut tmp: Vec<i64> = vec![];
        for j in 0..sv.len() {
            let p = sv[j].pop().unwrap();
            tmp.push(p);
        }
        for j in i..i + (k - tmp.len() as i64) {
            tmp.push(j);
            i += 1;
        }
        ret.push(tmp.clone());
        sv.push(tmp);
    }
    for j in 0..ret.len() {
        print!("{} ", ret[j].len());
        println!("{}", join(&ret[j], " "));
    }
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 7548
#include <iostream>

using namespace std;

// Function to trace intermediate result
void trace(int A[], int n)
{
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

void bubbleSort(int A[], int n)
{
	int counter = 0;
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
				int tmp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = tmp;
				counter++;
			}
		}
	}

	trace(A, n);
	cout << counter << endl;
}

int main()
{
	int A[100];
	int n;
	int key;
	int j;
	// Input data 
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];

	bubbleSort(A, n);

	return 0;
}

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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;

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

  string s; cin >> s;
  int ans = 0;
  int cnt = 0;
  for(int i = 0; i < s.size(); i++)
  {

    if(s[i] == 'A' || s[i] == 'C' || s[i] =='G' || s[i] == 'T')
      cnt++;
    else{
      ans= max(ans, cnt);
      cnt = 0;
    }
  }

  cout << max(ans,cnt) << nl;
  return 0;
}




Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,k;
    cin >> a >> b >> k;
    int i,j;
    
    for(i=a;i<=min(a+k-1,b);i++){
        cout << i << endl;
    }
        
    for(j=max(b-k+1,a+k);j<=b;j++){
        cout << j << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

# セグメント木
# senment-tree

N, Q = map(int, input().split())
QUERY = [input().split() for _ in range(Q)]


class SegmentTree:
    """
    引数：
        N: 処理する区間の長さ
        operator: モノイド演算 (max, min, __add__,ラムダ式,関数定義など)
        UNIT: 単位元
        a: 長さNの配列 a で初期化（a を与えない場合、単位元で初期化）
    注意: 内部的には 1-indexed
    """

    def __init__(self, N, operator, unit, a=None):
        self.op = operator
        self.UNIT = unit

        self.N0 = 2**(N-1).bit_length()
        self.tree = [self.UNIT]*(2*self.N0)
        if a != None:
            self.tree[self.N0:self.N0+N] = a[:]
            for k in range(self.N0-1, 0, -1):
                self.tree[k] = self.op(self.tree[2*k], self.tree[2*k+1])

    # a_k の値を x に更新
    def update(self, k, x):
        k += self.N0
        self.tree[k] = x
        k //= 2
        while k:
            self.tree[k] = self.op(self.tree[2*k], self.tree[2*k+1])
            k //= 2

    # 区間[l,r)をopでまとめる
    def query(self, l, r):
        L = l + self.N0
        R = r + self.N0
        s = self.UNIT
        while L < R:
            if R & 1:
                R -= 1
                s = self.op(self.tree[R], s)
            if L & 1:
                s = self.op(s, self.tree[L])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def get(self, k):  # k番目の値を取得。query[k,k]と同じ
        return self.tree[k + self.N0]

    def all(self):
        return self.tree[1]


#####単位元######
INF = 2 ** 31 - 1
x = [INF] * N
#seg = SegmentTree(x, segfunc=min, ide_ele=INF)
seg = SegmentTree(N, min, INF)

ans = []

for com, x, y in QUERY:
    x, y = int(x), int(y)

    if com == '0':
        seg.update(x, y)
    else:
        q = seg.query(x, y + 1)
        ans.append(str(q))


print("\n".join(ans))



Measured memory_bytes: 40080
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 1000;
int a[maxn], b[maxn], c[maxn];
int n;

int erfen1(int key)
{
	int left = 0, right = n - 1;
	while (left <= right)
	{
		int mid = (left + right) >> 1;
		if (c[mid] > key) right = mid - 1;
		else if (c[mid] <= key) left = mid + 1;
	}
	return left;
}

int erfen2(int key)
{
	int left = 0, right = n - 1;
	while (left <= right) {
		int mid = (left + right) >> 1;
		if (a[mid] >= key) right = mid - 1;
		else if (a[mid]<key) left = mid + 1;
	}
	return right;
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	for (int i = 0; i < n; i++) scanf("%d", &b[i]);
	for (int i = 0; i < n; i++) scanf("%d", &c[i]);
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	ll ans = 0;
	for (int i = 0; i<n; i++) {
		int p1 = erfen2(b[i]);
		int p2 = erfen1(b[i]);
		ll p = lower_bound(a, a + n, b[i]) - a;
		ll q = upper_bound(c, c + n, b[i]) - c;
		ans += p*(n - q);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1408
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
template<class T> inline T popFirst(multiset<T> &a){
  T res = *(a.begin());
  a.erase(a.begin());
  return res;
}
template<class T> inline T popFirst(set<T> &a){
  T res = *(a.begin());
  a.erase(a.begin());
  return res;
}
int N;
int z;
int num[1000000];
int now[1000000];
int sz;
int main(){
  int Lj4PdHRW;
  int i;
  int k;
  int c;
  multiset<int> s;
  multiset<int>::iterator it;
  rd(N);
  z = 1<<N;
  for(Lj4PdHRW=0;Lj4PdHRW<(z);Lj4PdHRW++){
    rd(k);
    s.insert(-k);
  }
  now[sz++] = popFirst(s);
  for(k=0;k<(N);k++){
    c = sz;
    for(i=0;i<(c);i++){
      it = s.upper_bound(now[i]);
      if(it==s.end()){
        wt_L("No");
        wt_L('\n');
        return 0;
      }
      now[sz++] = *it;
      s.erase(it);
    }
  }
  wt_L("Yes");
  wt_L('\n');
  return 0;
}
// cLay varsion 20190914-1

// --- original code ---
// int N, z;
// int num[1d6];
// int now[1d6], sz;
// {
//   int i, k, c;
//   multiset<int> s;
//   multiset<int>::iterator it;
//   
//   rd(N);
//   z = 1<<N;
//   rep(z){
//     rd(k);
//     s.insert(-k);
//   }
// 
//   now[sz++] = popFirst(s);
//   rep(k,N){
//     c = sz;
//     rep(i,c){
//       it = s.upper_bound(now[i]);
//       if(it==s.end()) wt("No"), return 0;
//       now[sz++] = *it;
//       s.erase(it);
//     }
//   }
// 
//   wt("Yes");
// }


Measured memory_bytes: 13568
using AtCoderBeginnerContest135.Questions;
using AtCoderBeginnerContest135.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest135.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var p = inputStream.ReadIntArray();

            var wrongCount = 0;
            for (int i = 0; i < p.Length; i++)
            {
                if (p[i] != i + 1)
                {
                    wrongCount++;
                }
            }

            if (wrongCount <= 2)
            {
                yield return "YES";
            }
            else
            {
                yield return "NO";
            }
        }
    }
}


namespace AtCoderBeginnerContest135
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest135.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest135.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

using namespace std;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}init;
typedef long long LL;
typedef vector<int> V;
typedef vector<V> VV;

template<typename T>
void chmin(T& a,T b){a=min(a,b);}
template<typename T>
void chmax(T& a,T b){a=max(a,b);}


#define PRO "YES"
#define SHUMI "NO"
#define fin "\n"
#define IL inline
IL void rot(V& C){
    swap(C[0],C[3]);
    swap(C[1],C[3]);
    swap(C[2],C[3]);
}
V min_rot(V C){
    auto res=C;
    for(int i=0;i<3;i++){
        rot(C);
        res=min(res,C);
    }
    return res;
}
int get_same(V C){
    if(C[0]==C[2]&&C[1]==C[3]){
        if(C[0]==C[1])return 4;
        else return 2;
    }
        
    return 1;
}
LL P(LL n,LL k){
    if(n<k)return 0;
    LL res=1;
    for(int i=0;i<k;i++)
        res*=n-i;
    return res;
}

int pos[4][4]={
    {1,0,1,0},
    {2,1,0,3},
    {3,2,3,2},
    {0,3,2,1}
};
LL mypow(LL a,LL n){
    LL res=1;
    while(n--){
        res*=a;
    }
    return res;
}
typedef pair<int,int> pi;
int main(){
    int N;
    cin>>N;
    VV C(N,V(4));
    for(auto &c:C){
        for(auto &it:c)cin>>it;
        c=min_rot(c);
    }
    map<V,int> cnt;
    LL res=0;
    for(int i=0;i<N;i++)cnt[C[i]]++;
    for(int i=0;i<N;i++){
        auto &now=C[i];
        cnt[C[i]]--;
        for(auto &it:cnt){
            if(it.second==0)continue;
            LL ans=0;
            V rev=it.first;
            it.second--;
            for(int j=0;j<4;j++){
                map<V,int> need;
                for(int t=0;t<4;t++){
                    need[min_rot({now[pos[t][0]],now[pos[t][1]],rev[pos[t][2]],rev[pos[t][3]]})]++;
                }
                LL K=1;
                for(auto &it:need)K*=mypow(get_same(it.first),it.second);
                for(auto &it:need){
                    if(cnt.count(it.first)==0)K=0;
                    else{                         
                        K*=P(cnt[it.first],it.second);
                    }
                } 
                ans+=K;
                rot(rev);  
            }
            it.second++;
            ans*=it.second;
            res+=ans;
        }       
    }
    cout<<res<<fin;
    return 0;
}


Measured memory_bytes: 384
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
tour=[0]
visited=[0]*n
visited[0]=1
next_town = 0
flag=False
for i in range(n):
    next_town=A[next_town]-1
    if i+1==k:
        flag = True
        ans = next_town
        break
    if next_town==0:
        first_roop_idx = 0
        break
    if visited[next_town]>0:
        first_roop_idx = visited[next_town]
        break
    tour.append(next_town)
    visited[next_town]=i+1
#print(tour)
#print(visited)
#print(first_roop_idx)
if not flag:
    if k<=len(tour):
        ans = tour[k]
    else:
        k-=first_roop_idx
        #print("k=",k)
        if len(tour)-first_roop_idx==0:
            k=0
        else:k=k%(len(tour)-first_roop_idx)
        #print("k=",k)
        ans = tour[first_roop_idx+k]
print(ans+1)
#print(flag)


Measured memory_bytes: 32388
using System;

class Program
{
    static void Main()
    {
        char[] character = new char[30];
        int[] count = new int[2000];
        for (int i = 0; i < 26; i++)
        {
            int unicode = 97 + i;
            character[i] = (char)unicode;
        }
        while (true)
        {
            string zeta = Console.ReadLine();
            if (zeta == null) break;
            char[] alpha = zeta.ToCharArray();
            for (int i = 0; i < alpha.Length; i++)
            {
                if (char.IsUpper(alpha[i]) == true) alpha[i] = char.ToLower(alpha[i]);
                for (int j = 0; j < 26; j++)
                    if (alpha[i] == character[j]) count[j] += 1;
            }
        }
        for (int j = 0; j < 26; j++)
        {
            Console.WriteLine(character[j] + " : " + count[j]);
        }
    }
}


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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef uint64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	int n=sz(s), ans =0;
	
	rep2(i,1,n/2){
		if(s.substr(0,i) == s.substr(i,i)) ans = i;
	
	}
	cout << ans*2 <<"\n";
	return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
ac = [0]*n
wa = [0]*n

for i in range(m):
  p,s = input().split()
  p = int(p)-1
  if s == 'AC':
     ac[p] = 1
  elif s == 'WA':
    if ac[p] == 0:
      wa[p] += 1

num_ac = 0
num_wc = 0

for a, w in zip(ac,wa):
  num_ac += a
  if a > 0:
    num_wc += w  
print(num_ac,num_wc)

Measured memory_bytes: 4596
N = int(input())
total = 0
S = [0] * N

for i in range(N):
  s = int(input())
  total += s
  S[i] = s
  
if str(total)[-1] != "0":
  print(total)
else:
  l = [i for i in S if str(i)[-1] != "0"]
  if len(l) > 0:
    print(total - min(l))
  else:
    print(0)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    //COMinit();
    int k,n;
    cin >> k >> n;
    V a(n);
    REP1(i,n) cin >> a[i];
    /*ll ans1 = 0;
    REPR(i,n){
        if(i==1) break;
        ans1 +=a[i]-a[i-1];
    }
    ll ans2 =0;
    ans2+=k-a[n]+a[1];
    FOR(i,2,n){
        ans2+=a[i]-a[i-1];
    }
    cout << min(ans1,ans2)<< endl;*/
    V d(n);
    int maxd = 0;
    REP(i,n){
        if(i==0){
           d[i]=k-a[n]+a[1]; 
        }
        else{
        d[i]=a[i+1]-a[i];
        }
        maxd = max(maxd,d[i]);
       // cout << i << " = " <<d[i] << endl;
    }
    cout << k-maxd << endl;
}

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

const int maxn = 2510, maxm = 5010, inf = 1e9;

#define fi first
#define se second
#define f(i, a, b) for (int i = a; i < b; ++i)
vector<pair<int, int> > g[maxn], gg[maxn];

int n, m, p;
int dis[maxn], inq[maxn], cnt[maxn];
int vis[maxn];

void dfs(int x) {
	if (vis[x]) return;
	vis[x] = 1;
	for (int i = 0; i < (int)gg[x].size(); ++i) {
		int y = gg[x][i].fi, z = gg[x][i].se;
		dfs(y);
		g[y].push_back(make_pair(x, z));
	}
}

int main() {
	cin >> n >> m >> p;
	int a, b, c;
	f(i, 0, m) {
		cin >> a >> b >> c;
		gg[b].push_back(make_pair(a, c-p));
	}
	dfs(n);
	//SPFA
	f(i, 2, n+1)
		dis[i] = -inf;
	queue<int> q;
	q.push(1);
	int x;
	while (!q.empty()) {
		x = q.front(); q.pop(); inq[x] = 0;
		if (++cnt[x] > m) break;
		f(i, 0, (int)g[x].size()) {
			int y = g[x][i].fi, z = g[x][i].se;
			if (dis[y] < dis[x]+z) {
				dis[y] = dis[x]+z;
				if (!inq[y]) {
					q.push(y);
					inq[y] = 1;
				}
			}
		}
	}
	if (cnt[x] > m) {
		cout << -1 << endl;
	}
	else {
		cout << max(0, dis[n]) << endl;
	}
}


Measured memory_bytes: 768
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Integer>[] g = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            g[i] = new ArrayList<>();
        }
        for (int i = 0; i < m; i++) {
            int v = sc.nextInt() - 1;
            int u = sc.nextInt() - 1;
            g[v].add(u);
        }
        int s = sc.nextInt() - 1;
        int t = sc.nextInt() - 1;
        int[][] d = new int[n][3];
        for (int i = 0; i < d.length; i++) {
            Arrays.fill(d[i], Integer.MAX_VALUE);
        }

        Queue<int[]> q = new LinkedList<>();
        q.offer(new int[]{s, 0});
        d[s][0] = 0;

        while (!q.isEmpty()) {
            int[] vx = q.poll();
            int v = vx[0];
            int state = vx[1];
            int next = (vx[1] + 1) % 3;
            for (int i = 0; i < g[v].size(); i++) {
                if (d[g[v].get(i)][next] != Integer.MAX_VALUE) continue;
                d[g[v].get(i)][next] = d[v][state] + 1;
                q.offer(new int[]{g[v].get(i), next});
            }
        }

        if (d[t][0] == Integer.MAX_VALUE) {
            System.out.println(-1);
            return;
        }

        System.out.println(d[t][0] / 3);
    }
}

Measured memory_bytes: 103180
import java.util.Scanner;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

    static int N;
    static long A;
    static long B;
    static long C;
    static int[] map;



    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        A = scanner.nextInt();
        B = scanner.nextInt();

        int ans = 0;

        if(A > B){
            A--;
        }

        System.out.println(A);


//        if(ans == 0){
//            System.out.println("Yes");
//        }else{
//            System.out.println("No");
//        }


    }

}



Measured memory_bytes: 21332
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()


int main() {
    string s;
    int n;
    cin>>n>>s;
    
    int cnt=0;
    rep(i,n-2){
        if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C') cnt++;
    }
    
    dunk(cnt);
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
//import java.util.Scanner;
//import java.io.InputStream;
//import java.io.IOException;
//import java.util.NoSuchElementException;
//import java.io.PrintWriter;
//import java.lang.Math;
//import java.io.BufferedReader;
//import java.io.InputStreamReader;
//import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args)
	{
		StringBuilder sb = new StringBuilder();
		
//		Scanner sc = new Scanner(System.in);
		FastScanner sc = new FastScanner();
		Util39 util = new Util39();
//		int n = sc.nextInt();
//		String s = sc.next();
//		int a[] = new int[3];
//		for (int ii = 0; ii < 3; ii++) a[ii] = sc.nextInt();
		
		
		
		int N = sc.nextInt();
		if (N % 2 == 0) sb.append(N);
		else sb.append(N * 2);
		
		
		
//		System.out.println(sb.toString());
		PrintWriter out = new PrintWriter(System.out);
		out.println(sb.toString());
		out.flush();
	}
}

class FastScanner {
    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 static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; 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();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

class Util39 {
	public int pow(int a, int b)
	{
		int r = 1;
		for (int i = 0; i < b; i++) r *= a;
		return r;
	}
}


Measured memory_bytes: 22612
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        if (A > 8 || B > 8) {
            System.out.println(":(");
        } else {
            System.out.println("Yay!");
        }
    }
}


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

using namespace std;

int main()
{
	int w, a, b;
	cin >> w >> a >> b;
	if (abs(a - b) <= w)
		cout << 0 << endl;
	else
		cout << abs(a - b) - w << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    char c = s.at(0);
    s.erase(s.begin());
    s.push_back(c);
    if (s == t) {
      Yes();
      return 0;
    }
  }
  No();
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        if (A <= 8 && B <= 8) {
            System.out.println("Yay!");
        }
        else {
            System.out.println(":(");
        }
    }
}


Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};

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

    deque<ll> deq;
    for(int i=0;i<n;i++){
        if(i % 2 == 0){
            deq.push_back(a[i]);
        }else{
            deq.push_front(a[i]);
        }
    }
    if(n%2!=0){
        while(deq.size()){
            ll ans = deq.back();
            deq.pop_back();
            cout << ans << " ";
        }
    }else{
        while(deq.size()){
            ll ans = deq.front();
            deq.pop_front();
            cout << ans << " ";
        }
    }
}

Measured memory_bytes: 5376
#include<cstdio>
#include<algorithm>
using namespace std;
static const int MAX_N = 200;
static const int MAX_R = 1000;
static const int INF = 1 << 20;

int N, M;
int x, y, t; char sl;
int R;
int z[MAX_R];

int dist1[MAX_N][MAX_N], dist2[MAX_N][MAX_N];
int memo[MAX_R][MAX_N];

int main(){
	for(;;){
		scanf("%d %d", &N, &M);
		if(N == 0 && M == 0) break;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				if(i == j){
					dist1[i][j] = 0;
					dist2[i][j] = 0;
				}else{
					dist1[i][j] = INF;
					dist2[i][j] = INF;
				}
			}
		}
		for(int i = 0; i < M; i++){
			scanf("%d %d %d %c", &x, &y, &t, &sl);
			x--; y--;
			if(sl == 'L'){
				dist1[x][y] = min(dist1[x][y], t);
				dist1[y][x] = min(dist1[y][x], t);
			}else if(sl == 'S'){
				dist2[x][y] = min(dist2[x][y], t);
				dist2[y][x] = min(dist2[y][x], t);
			}
		}
		for(int k = 0; k < N; k++){
			for(int i = 0; i < N; i++){
				for(int j = 0; j < N; j++){
					if(dist1[i][j] > dist1[i][k] + dist1[k][j]) dist1[i][j] = dist1[i][k] + dist1[k][j];
					if(dist2[i][j] > dist2[i][k] + dist2[k][j]) dist2[i][j] = dist2[i][k] + dist2[k][j];
				}
			}
		}
		scanf("%d", &R);
		for(int i = 0; i < R; i++){
			scanf("%d", &z[i]);
			z[i]--;
		}
		fill(memo[0], memo[R], INF);
		for(int i = 0; i < R; i++){
			for(int j = 0; j < N; j++){
				if(i == 0){
					if(j == z[i]) memo[i][j] = 0;
				}else{
					memo[i][j] = min(memo[i][j], min(memo[i - 1][j] + dist1[z[i - 1]][z[i]], INF));
					for(int k = 0; k < N; k++){
						memo[i][k] = min(memo[i][k], min(memo[i - 1][j] + dist1[z[i - 1]][j] + dist2[j][k] + dist1[k][z[i]], INF));
					}
				}
			}
		}
		int res = INF;
		for(int i = 0; i < N; i++) res = min(res, memo[R - 1][i]);
		printf("%d\n", res);
	}
	return 0;
}



Measured memory_bytes: 3720
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
edges = 2
cnt = 1
ans = 1
for i in range(N-1):
    if A[i] == A[i+1]:
        cnt += 1
        continue
    if edges == 2 and cnt >= 4:
        edges -= 2
        ans *= A[i] * A[i]
    elif cnt >= 2:
        edges -= 1
        ans *= A[i]
    if edges == 0:
        break
    cnt = 1
if edges == 2 and cnt >= 4:
    edges -= 2
    ans *= A[i] * A[i]
elif edges == 1 and cnt >= 2:
    edges -= 1
    ans *= A[i]
if edges == 0:
    print(ans)
else:
    print(0)


Measured memory_bytes: 14672
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  using P = pair<Int, Int>;
  vector<P> vp;
  for(Int i=0;i<n;i++){
    Int x,y;
    cin>>x>>y;
    vp.emplace_back(x,y);
  }
  sort(vp.begin(),vp.end());
  for(auto p:vp) cout<<p.first<<" "<<p.second<<endl;
  return 0;
}



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

char S[100010];

void r(int i){
	if(S[i]=='1') S[i]='0';
	else S[i]='1';
}

int main(void){
	scanf("%s",S);
	int n = strlen(S);
	int ans=0;
	for(int i=0;i<n-1;i++){
		char a=S[i],b=S[i+1];
		if(a==b){
			ans++;
			r(i+1);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List

main = do
  n <- readLn :: IO Int
  when (n /= 0) $ do
    xs <- input n read :: IO [Int]
    print $ solve xs
    main
    
solve :: [Int] -> Int
solve (x:xs) = mss [x] xs

mss :: [Int] -> [Int] -> Int
mss ls [] = maximum ls
mss ls (x:xs) | w > x = mss (w:ls) xs
              | otherwise = mss (x:ls) xs
  where
    w = head ls + x

input :: Int -> (String -> a) -> IO [a]
input n f = map f <$> replicateM n getLine

Measured memory_bytes: 5520
object Main {
  def main(args: Array[String]): Unit = {
    val in: String = scala.io.StdIn.readLine();
    val S = in.toInt;
    val h = S / 60 / 60;
    val m = (S % 3600) / 60;
    val s = S % 60;
    println(h + ":" + m + ":" + s);
  }
}

Measured memory_bytes: 43828
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから----------- 
int main(void){
    ld a, b, h, m;
    cin >> a >> b >> h >> m;

    ld minutesd = 360 / 60 * m;

    ld mm = minutesd / 360;

    mm *= 30;

    ld hoursd = 360 / 12 * h;

    hoursd += mm;

    ld degree = min(abs(minutesd - hoursd), 360 - abs(minutesd - hoursd));

    degree = degree * M_PI / 180;

    //cout << minutesd << " " << hoursd << " " << degree << endl;

    ld ans = pow(a, 2) + pow(b, 2) - 2 * a * b * cos(degree);

    cout << fixed << setprecision(15) << sqrt(ans) << endl;


}


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

int main(){
    int H,A,B;cin >> H >> A >> B;
    LL ans = 0;
    for(int a = A;a <= B;a++){
        if(H%a == 0)ans++;
    }
    cout<<ans<<endl;
}
//2t+2



Measured memory_bytes: 3108
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <math.h>
 
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;
 
 
int main(){
	int n,m;
	cin>>n>>m;
	ll x[1010],y[1010],z[1010];
	REP(i,n)cin>>x[i]>>y[i]>>z[i];
	ll ans=0;
	REP(i,8){
		ll res=0;
		vector<ll>v;
		REP(j,n){
			ll a=0;
			if(i&1)a+=x[j];
			else a-=x[j];
			if((i>>1)&1)a+=y[j];
			else a-=y[j];
			if((i>>2)&1)a+=z[j];
			else a-=z[j];
			v.PB(a);
		}
		sort(ALL(v));
		reverse(ALL(v));
		REP(j,m)res+=v[j];
		ans=max(ans,res);
	}
	cout<<ans<<endl;
}

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

signed main(){
  int N,T;
  cin>>N>>T;
  int ans=T;
  std::vector<int> t(N);
  for(int i=0;i<N;i++)cin>>t[i];
  for(int i=1;i<N;i++){
    if(t[i-1]+T<t[i])ans+=T;
    else ans+=t[i]-t[i-1];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
N,x = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
#x個のお菓子を配る。
#和がxを越えないように最も多い数のaを選ぶ
A.sort()
ans = 0
cur = 0
for a in A:
    cur += a
    if cur > x:
        print(ans)
        exit()
    ans += 1
if cur == x:print(N)
else:print(ans-1)

Measured memory_bytes: 38256
#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
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class 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=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    cout<<t+s<<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, k, i, next, count, check uint64
	fmt.Scan(&n, &k)
	var a []uint64 = make([]uint64, n)
	var b []uint64 = make([]uint64, 0)
	c := make(map[uint64]uint64)
	for i = 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	next = 1
	c[1] = 1
	b = append(b, 1)
	for i = 0; i < k; i++ {
		b = append(b, a[next-1])
		next = a[next-1]
		count++
		if c[next] > 0 {
			if next == 1 {
				check = k % count
				if check == 0 {
					fmt.Println(b[count])
					return
				}
				fmt.Println(b[check])
				return
			}
			check = count - c[next]
			check = (k - count) % check
			if check == 0 {
				fmt.Println(b[count])
				return
			}
			fmt.Println(b[c[next]+check])
			return

		}
		c[next] = count
	}

	fmt.Println(b[k])
}


Measured memory_bytes: 19072