akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 10000000
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func powMod(a, n int) int {
	if n < 0 {
		log.Fatal("pow error")
	}
	if n == 0 {
		return 1
	}
	if n%2 == 0 {
		d := powMod(a, n/2) % mod
		return d * d % mod
	}
	return a * powMod(a, n-1) % mod
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

type key struct {
	Positive bool
	First    int
	Second   int
}

func toPositive(a, b int) (int, int, bool) {
	if a == 0 && b == 0 {
		return a, b, true
	}
	if a == 0 {
		if b > 0 {
			return a, b, true
		}
		return a, -b, false
	}

	if b == 0 {
		if a > 0 {
			return a, b, true
		}
		return -a, b, false
	}

	if a > 0 && b > 0 {
		return a, b, true
	}
	if a > 0 && b < 0 {
		return a, -b, false
	}
	if a < 0 && b > 0 {
		return -a, b, false
	}
	if a < 0 && b < 0 {
		return -a, -b, true
	}
	log.Fatal("positive error")
	return 0, 0, true
}

const mod = 1000000007

func main() {
	n := nextInt()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		b[i] = nextInt()
	}

	count := make(map[key]int)
	twoZeroes := 0
	for i := 0; i < n; i++ {
		var val key
		if a[i] == 0 && b[i] == 0 {
			twoZeroes++
			continue
		} else if a[i] == 0 {
			val = key{true, 0, 1}
		} else if b[i] == 0 {
			val = key{false, 1, 0}
		} else {
			pa, pb, pos := toPositive(a[i], b[i])
			g := gcd(pa, pb)
			val = key{pos, pa / g, pb / g}
		}
		count[val]++
	}

	ans := 1
	used := make(map[key]bool)
	for k, cnt := range count {
		if used[k] {
			continue
		}

		pair := key{!k.Positive, k.Second, k.First}
		if pcnt, ok := count[pair]; ok {
			ans *= (powMod(2, cnt) + powMod(2, pcnt) - 1 + mod) % mod
			used[pair] = true
		} else {
			ans *= powMod(2, cnt)
		}
		ans %= mod
	}
	ans += twoZeroes % mod
	ans = (ans - 1 + mod) % mod
	fmt.Println(ans)
}


Measured memory_bytes: 25880
#include <iostream>

using namespace std;

const int LIM=1000*100;
long int valeurs[LIM],multiples[LIM];

int main(){
    int n;
    long long int compteur=0,valeur,multiple;
    cin >> n;

    for(int i=0;i<n;i++) cin >> valeurs[i] >> multiples[i];

    for(int i=n-1;i>=0;i--){
        valeur=valeurs[i]+compteur;
        multiple=multiples[i];
        compteur+= (multiple-(valeur%multiple))%multiple;
        }
    cout << compteur << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int h,w;
  cin>>h>>w;
  vector<vector<int>> c(10,vector<int>(10));
  for (int i = 0; i < 10; ++i)
  {
    for (int j = 0; j < 10; ++j)
    {
      cin>>c[i][j];
    }
  }

  //Warshall_Floyd
  for (int k = 0; k < 10; ++k)
  {
    for (int i = 0; i < 10; ++i)
    {
      for (int j = 0; j < 10; ++j)
      {
        c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
      }
    }
  }
  int64_t cost=0;
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      int tmp;
      cin>>tmp;
      if(abs(tmp)==1) continue;
      cost+=c[tmp][1];
    }
  }
  cout<<cost;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int main()
{
    string s;
    cin >> s;
    int n = s.length();
    reverse(s.begin(), s.end());
    for (int i = 0; i < n;) {
        if (s[i] == 'm' && s[i + 1] == 'a' && s[i + 2] == 'e' && s[i + 3] == 'r' && s[i + 4] == 'd') {
            i += 5;
        } else if (s[i] == 'e' && s[i + 1] == 's' && s[i + 2] == 'a' && s[i + 3] == 'r' && s[i + 4] == 'e') {
            i += 5;
        } else if (s[i] == 'r' && s[i + 1] == 'e' && s[i + 2] == 'm' && s[i + 3] == 'a' && s[i + 4] == 'e' && s[i + 5] == 'r' && s[i + 6] == 'd') {
            i += 7;
        } else if (s[i] == 'r' && s[i + 1] == 'e' && s[i + 2] == 's' && s[i + 3] == 'a' && s[i + 4] == 'r' && s[i + 5] == 'e') {
            i += 6;
        } else {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(void)
{
  string a,b,c; cin>>a>>b>>c;
  int i=0,j=0,k=0;
  char moji='a';
  
  for(;;){
    if(moji=='a'){moji=a[i]; i++;}
    else if(moji=='b'){moji=b[j]; j++;}
    else if(moji=='c'){moji=c[k]; k++;}
    
    if(i==(a.size()+1)){puts("A"); break;}
    if(j==(b.size()+1)){puts("B"); break;}
    if(k==(c.size()+1)){puts("C"); break;}
  }
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;

int h, w;
int pred[2020][2020];
int preu[2020][2020];
int prel[2020][2020];
int prer[2020][2020];
int solve(int y, int x){
    int sm = 0;
    sm += pred[y][x];
    sm += preu[y][x];
    sm += prel[y][x];
    sm += prer[y][x];
    return sm+1;
}

void print(int pre[2020][2020]){
    rep(i,0,h){
        rep(x,0,w){
            cout << pre[i][x] << ' ';
        }cout << endl;
    }cout << endl;
}

int main()
{
    cin.sync_with_stdio(false);
    cin >> h >> w;
    vector<string> mp(h);
    rep(i,0,h){
        cin >> mp[i];
    }
    rep(i,0,h){
        int sm = 0;
        rep(x,0,w){
            if(mp[i][x] == '.'){
                sm++;
                prel[i][x] = sm-1;
            }else{
                sm = 0;
                prel[i][x] = 0;
            }
        }
    }
    //print(prel);
    rep(i,0,h){
        int sm = 0;
        rep(r,0,w){
            int x = w-r-1;
            if(mp[i][x] == '.'){
                sm++;
                prer[i][x] = sm-1;
            }else{
                sm = 0;
                prer[i][x] = 0;
            }
        }
    }
    //print(prer);
    rep(x,0,w){
        int sm = 0;
        rep(i,0,h){
            if(mp[i][x] == '.'){
                sm++;
                preu[i][x] = sm-1;
            }else{
                sm = 0;
                preu[i][x] = 0;
            }
        }
    }
    //print(preu);
    rep(x,0,w){
        int sm = 0;
        rep(r,0,h){
            int i = h-r-1;
            if(mp[i][x] == '.'){
                sm++;
                pred[i][x] = sm-1;
            }else{
                sm = 0;
                pred[i][x] = 0;
            }
        }
    }
    //print(pred);
    int mx = 0;
    rep(i,0,h){
        rep(x,0,w){
            mx = max(mx, solve(i,x));
        }
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 68096
# -*- coding: utf-8 -*-
import sys 
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().decode()

st = ['SS','SW','WS','WW']

# 8通りの分岐を辞書に登録
d = defaultdict(int)
d['SSo'] = 'S'
d['SSx'] = 'W'
d['SWo'] = 'W'
d['SWx'] = 'S'
d['WSo'] = 'W'
d['WSx'] = 'S'
d['WWo'] = 'S'
d['WWx'] = 'W'
 

#答えの候補をansに代入
ans = []
for s in st:
    t = s  
    for i in range(1,N-1):
        tmp = t[-2:]
        ss = tmp + S[i]
        t += d[ss]
    ans.append(t)

# 答えの候補が矛盾しないかのチェック
for a in ans:
    b = a[N-2]+a[N-1]+S[N-1]
    if d[b] != a[0]:
        continue
    b = a[N-1]+a[0]+S[0]
    if d[b] != a[1]:
        continue
    print(a)
    sys.exit()

print(-1)

Measured memory_bytes: 10088
#include<iostream>
using namespace std;
int N,K;
int X[2<<17];
int dL[20][2<<17],dLs[20][2<<17];
int dR[20][2<<17],dRs[20][2<<17];
int Q;
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)cin>>X[i];
	int l=0;
	for(int i=0;i<N;i++)
	{
		while(l<N&&X[l]<X[i]+K)l++;
		dL[0][i]=l;
		dLs[0][i]=i;
	}
	int r=N-1;
	for(int i=N;i--;)
	{
		while(r>=0&&X[r]>X[i]-K)r--;
		dR[0][i]=r;
		dRs[0][i]=i;
	}
	for(int k=0;k<19;k++)
	{
		for(int i=0;i<N;i++)
		{
			if(dL[k][i]==N)
			{
				dL[k+1][i]=N;
				dLs[k+1][i]=dLs[k][i];
			}
			else
			{
				dL[k+1][i]=dL[k][dL[k][i]];
				dLs[k+1][i]=dLs[k][i]+dLs[k][dL[k][i]];
			}
			if(dR[k][i]==-1)
			{
				dR[k+1][i]=-1;
				dRs[k+1][i]=dRs[k][i];
			}
			else
			{
				dR[k+1][i]=dR[k][dR[k][i]];
				dRs[k+1][i]=dRs[k][i]+dRs[k][dR[k][i]];
			}
		}
	}
	cin>>Q;
	for(;Q--;)
	{
		int L,R;cin>>L>>R;
		L--;
		int cnt=1,now=L;
		int ans=0;
		for(int k=20;k--;)
		{
			if(dL[k][now]<R)
			{
				cnt+=1<<k;
				ans-=dLs[k][now];
				now=dL[k][now];
			}
		}
		ans-=now;
		now=R-1;
		for(int k=20;k--;)
		{
			if(dR[k][now]>=L)
			{
				ans+=dRs[k][now];
				now=dR[k][now];
			}
		}
		ans+=now;
		cout<<ans+cnt<<endl;
	}
}


Measured memory_bytes: 67152
/**
 * @author Video Vocabulary
 * @date 2020-06-21 18:09:37
 */
#include <bits/stdc++.h>

using namespace std;

void solve() {
    
}

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

    char c;
    cin >> c;
    cout << (c>=97?"a":"A") << endl;
}


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


def main():
    from math import degrees, atan

    a, b, x = map(int, input().split())
    h = x / (a ** 2)
    y = 2 * h * a / b
    z = 2 * b - 2 * h

    if x == (a ** 2) * b:
        print(0)
    elif 2 * h >= b:
        print(90 - degrees(atan(a / z)))
    else:
        print(degrees(atan(b / y)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
H, W = map(int, input().split())
S = [input() for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            continue
        k = 0
        for x, y in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
            if x < 0 or x >= H:
                continue
            if y < 0 or y >= W:
                continue
            if S[x][y] == "#":
                k += 1
        if k == 0:
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 3064
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat Dec  8 00:42:51 2018
//
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	for i := 0; i <= N; i += 4 {
		for j := 0; j <= N; j += 7 {
			if N == i+j {
				fmt.Println("Yes")
				return
			}
		}
	}

	fmt.Println("No")
}


Measured memory_bytes: 512
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end


S = s()
len = S.length

min = 1000000
(len-1).times{|i|
  if S[i+1] != S[i]
    max = (i+1) > (len-i-1) ? (i+1) : (len-i-1)
    min = max < min ? max : min
  end
}
if min == 1000000
  if S[0] == "0"
    puts len
  else
    puts len
  end
else
  puts min
end

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

int main() {
  int r = 0, g = 0, b = 0, n = 0;
  cin >> r >> g >> b >> n;
  
  int res = 0;
  for(int i = 0; i * r <= n; ++i) {
    for(int j = 0; j * g <= n; ++j) {
      int rem = n - i * r - j * g;
      if(rem >= 0 && rem % b == 0) {
        res += 1;
      }
    }
  }
  cout << res << endl;
  return 0;
}
      


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N, A;
    cin >> N >> A;
    if (N % 500 > A) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readInt
  val f = Iterator.continually(StdIn.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .toArray
  val p = Iterator.continually(StdIn.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .toArray

  val MIN = Int.MinValue

  val ans =
    (1 until 1 << 10)./:(MIN)((ans,key) => {
      val itp = p.iterator
      val score = 
        f./:(0)((fac,fe) => {
          val itf = fe.iterator
          val arr = itp.next
          val d = (0 until 10)./:(0)((acc,i) => {
            if(((key>>i & 1) & itf.next) == 1) acc + 1
            else acc
          })
          fac + arr(d)
        })
      math.max(ans, score)
    })

  println(ans)
}

Measured memory_bytes: 41420
#include <iostream>
#include <algorithm>

using namespace std;

int search(int a, int b, int c)
{
	if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
	{

	}
	else if (a % 2 == 1 && b % 2 == 1 && c % 2 == 1)
	{

	}
	else
		return 100000;

	int num = 0;

	int mi, ma;

	while (true)
	{
		if (a == b && a == c)
			return num;

		mi = min(a, (min(b, c)));
		ma = max(a, (max(b, c)));

		if (a <= b && a < c)
		{
			a += ma - mi;
			num += (ma - mi) / 2;
		}
		else if (a < b && a <= c)
		{
			a += ma - mi;
			num += (ma - mi) / 2;
		}
		else if (b <= a && b < c)
		{
			b += ma - mi;
			num += (ma - mi) / 2;
		}
		else if (b < a && b <= c)
		{
			b += ma - mi;
			num += (ma - mi) / 2;
		}
		else if (c <= b && c < a)
		{
			c += ma - mi;
			num += (ma - mi) / 2;
		}
		else if (c < b && c <= a)
		{
			c += ma - mi;
			num += (ma - mi) / 2;
		}
	}
}

int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;

	int best = 100000;

	int table_a[] = { 0,1,1,0 };
	int table_b[] = { 0,1,0,1 };
	int table_c[] = { 0,0,1,1 };
	int table_num[] = { 0,1,1,1 };

	for (int i = 0; i < 4; i++)
	{
		int ans = table_num[i] + search(a + table_a[i], b + table_b[i], c + table_c[i]);

		if (ans < best)
			best = ans;
	}

	cout << best << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var xyabc = Console.ReadLine().Split(' ');
            var x = int.Parse(xyabc[0]);
            var y = int.Parse(xyabc[1]);
            var a = long.Parse(xyabc[2]);
            var b = long.Parse(xyabc[3]);
            var c = long.Parse(xyabc[4]);

            var p = (from bb in Console.ReadLine().Split(' ') select long.Parse(bb)).ToList();
            var q = (from bb in Console.ReadLine().Split(' ') select long.Parse(bb)).ToList();
            var r = (from bb in Console.ReadLine().Split(' ') select long.Parse(bb)).ToList();

            while (p.Count <= x) p.Add(0);
            while (q.Count <= y) q.Add(0);

            p.Sort(func);
            q.Sort(func);
            r.Sort(func);

            p.RemoveRange(x, p.Count - x);
            q.RemoveRange(y, q.Count - y);

            x--;
            y--;

            foreach (var cc in r)
            {
                if (x == -1 && y != -1)
                {
                    if (q[y] < cc) q[y--] = cc;
                    continue;
                }
                if (y == -1 && x != -1)
                {
                    if (p[x] < cc) p[x--] = cc;
                    continue;
                }
                if (p[x] < q[y])
                {
                    if (p[x] < cc) p[x--] = cc;
                }
                else
                {
                    if (q[y] < cc) q[y--] = cc;
                }
            }

            Console.WriteLine((from dd in p select dd).Sum() + (from dd in q select dd).Sum());
        }

        private static int func(long x, long y)
        {
            return (int)(y - x);
        }
    }
}

Measured memory_bytes: 41848
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    sort(all(a));
    vp v;
    v.eb(a[0],1);
    rep2(i,1,n) {
        if(a[i-1] == a[i]) v.back().second++;
        else v.eb(a[i],1);
    }
    int sz = v.size();
    int ans = 0;
    rrep(i,sz) {
        int j = 1;
        while(j <= v[i].first) j *= 2;
        j -= v[i].first;
        assert(j <= v[i].first);
        while(v[i].second > 0) {
            if(j == v[i].first) {
                if(v[i].second >= 2) {
                    v[i].second -= 2;
                    ans++;
                    continue;
                } else break;
            } else {
                auto it = lower_bound(all(v),j,[](P p,int val){ return p.first < val;});
                if(it == v.end() or it->first > j) break;
                if(it->second == 0) break;
                it->second--;
                ans++;
                v[i].second--;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  double W, H, x, y;
  cin >> W >> H >> x >> y;
  auto ans1 = W * H / 2;
  int ans2 = (W / 2 == x && H / 2 == y) ? 1 : 0;
  cout << ans1 << " " << ans2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    long long int n,m,c=0;

    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&m);
        c=c^m;
    }
    if(c==0)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  int cnt = 0, ans = 0;
  rep(i, N-1) {
    if(H[i] >= H[i+1])
      cnt++;
    else {
      chmax(ans, cnt);
      cnt = 0;
    }
  }
  chmax(ans, cnt);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;
template <class T> inline void chmax(T & a, T const & b) { a = max(a, b); }

int main() {
    // input
    int n; cin >> n;
    vector<int> l(n), r(n);
    REP (i, n) cin >> l[i] >> r[i];

    // solve
    sort(l.rbegin(), l.rend());
    sort(ALL(r));
    ll acc = 0;
    ll t = 0;
    REP (i, n) {
        chmax(acc, t + l[i]);
        chmax(acc, t - r[i]);
        chmax(acc, t + l[i] - r[i]);
        t += l[i] - r[i];
    }

    // output
    cout << 2 * acc << endl;
    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  int x = A;
 for (int i = 0; i < (B-A+1); i++) {
   int a = x/10000; // 10000
   int e = x%10; // 1
   int b = x/1000-x/10000*10; // 1000
   int d = x/10-x/100*10; // 10
   if((a == e) && (b == d))
     count ++;
   x ++;
 }
  cout << count << endl;
}

Measured memory_bytes: 3516
N, K = gets.split.map(&:to_i)
if K > N * (N - 1) / 2 - (N - 1)
  p -1
  exit
end
a = N * (N - 1) / 2 - (N - 1) - K
p a + N - 1
2.upto(N) do |i|
  puts "1 #{i}"
end
i = 2
j = 3
while a > 0
  puts "#{i} #{j}"
  a -= 1
  if j < N
    j += 1
  else
    i += 1
    j = i + 1
  end
end

Measured memory_bytes: 1788
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define FOR1(n) for(int i=0;i<n;i++)
#define FOR2(j, n) for(int j=0;j<n;j++)
#define FOR3(i, m, n) for(int i=m;i<=n;i++)
#define ALL(c) c.begin(), c.end()
#define SCANF(x) scanf("%lld", &x)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	
	bool ends;
	map<char, bool> mp;
	int char_count = 0, char_count_in = 0;
	
	if(s[0] == s[s.size()-1]){
		ends = true;
	}else{
		ends = false;
	}
	
	FOR1(s.size()){
		if(!mp[s[i]]){
			//if(i != 0 && i != s.size() - 1) char_count_in++;
			char_count++;
			mp[s[i]] = true;
		}
	}
	
	if(ends && char_count <= 2){
		cout << "Second";
	}else{
		int size = s.size() - 2;
		if(ends){
			size -= 1;
		}
		if(size % 2 == 1){
			cout << "First";
		}else{
			cout << "Second";
		}
	}
}

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

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

	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[2]==a[0]+a[1]) {
		cout << "Yes";
	}
	else cout << "No";
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m, q;

char s[2000][2001];
int c[2001][2001];
int v[2001][2001];
int h[2001][2001];

int main() {
	cin >> n >> m >> q;
	inc(i, n) { scanf("%s", s[i]); }
	
	inc1(i, n) {
	inc1(j, m) {
		c[i][j] = s[i - 1][j - 1] - '0';
		v[i][j] = (j < 2 ? 0 : s[i - 1][j - 1] == '1' && s[i - 1][j - 2] == '1');
		h[i][j] = (i < 2 ? 0 : s[i - 1][j - 1] == '1' && s[i - 2][j - 1] == '1');
	}
	}
	inc1(i, n) {
	inc1(j, m) {
		c[i][j] += c[i - 1][j];
		v[i][j] += v[i - 1][j];
		h[i][j] += h[i - 1][j];
	}
	}
	inc1(i, n) {
	inc1(j, m) {
		c[i][j] += c[i][j - 1];
		v[i][j] += v[i][j - 1];
		h[i][j] += h[i][j - 1];
	}
	}
	
	inc(qq, q) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		x1--;
		y1--;
		
		#define R(a, x1, y1, x2, y2) (a[x2][y2] - a[x1][y2] - a[x2][y1] + a[x1][y1])
		int C = R(c, x1    , y1    , x2, y2);
		int V = R(v, x1    , y1 + 1, x2, y2);
		int H = R(h, x1 + 1, y1    , x2, y2);
		
		printf("%d\n", C - V - H);
	}
	
	return 0;
}


Measured memory_bytes: 52608
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
#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 VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

using mint = modint998244353;

struct S {
  mint x, power;
  S(mint x=0, mint power=1):x(x),power(power) {}
};
S op(S l, S r) { return S{l.x * r.power + r.x, l.power * r.power}; }
S e() { return S{0, 1}; }

struct F { int d; };
S mapping(F f, S s) {
  if(f.d == 0) return s;
  return S{(s.power-1)/9 * f.d, s.power};
}
F composition(F f, F g) {
  if( f.d == 0) return g;
  else return f;
}
F id() { return F{0}; }

int main() {
  int n,q; cin >> n >> q;
  lazy_segtree<S, op, e, F, mapping, composition, id> t(n);
  rep(i,n) t.set(i, S(1,10));
  rep(i,q) {
    int l, r, d;
    cin >> l >> r >> d; --l;
    t.apply(l, r, F{d});
    S ans = t.prod(0,n);
    printf("%d\n", ans.x.val());
  }
}


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

#include <math.h>
#include <stdlib.h>


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

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int r; cin >> r;
    cout << r * r << endl;

    return 0;
}


Measured memory_bytes: 256
from math import gcd
from numba import njit

K = int(input())

@njit
def solve():
    ans = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                ans += gcd(gcd(i, j), k)
    return ans
print(solve())

Measured memory_bytes: 110192
#include <bits/stdc++.h>
#define ll long long
using namespace std;
set<string> S;
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        S.insert(s);
    }
    cout << S.size() << '\n';
    return 0;
}

Measured memory_bytes: 19176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;

ll a[100100];
ll ans = INF;

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (i >= 1)a[i] += a[i - 1];
	}
	ll num = 0;
	ll k = 0;
	rep(i, n) {
		ll nn = a[i] + k;
		if (i % 2 == 0) {
			if (nn >= 0) {
				num += nn + 1;
				k -= nn + 1;
			}
		}
		else {
			if (nn <= 0) {
				num += abs(nn) + 1;
				k += abs(nn) + 1;
			}
		}
		//cout << k << " ";
	}
	//cout << endl;

	ans = min(ans, num);
	num = 0;
	k = 0;
	rep(i, n) {
		ll nn = a[i] + k;
		if (i % 2 == 0) {
			if (nn <= 0) {
				num += abs(nn) + 1;
				k += abs(nn) + 1;
			}
		}
		else {
			if (nn >= 0) {
				num += nn + 1;
				k -= nn + 1;
			}
		}
		//cout << k << " ";
	}
	ans = min(ans, num);
	//cout << endl;

	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

const int MAX_V = 10000;

vector<int> g[MAX_V]; //??°??????
vector<int> tp; //????????????????????????????????????

void bfs(int s, int indeg[MAX_V], bool used[MAX_V]){
    queue<int> q;

    q.push(s);
    used[s] = true;

    while(not q.empty()){
        int u = q.front(); q.pop();
        tp.emplace_back(u);
        rep(i,g[u].size()){
            int v = g[u][i];
            indeg[v]--;
            if(indeg[v] == 0 && not used[v]){
                used[v] = true;
                q.push(v);
            }
        }
    }
}

//??°??????????????????????????´??????0?????????
bool topologicalSort(int v){
    int indeg[MAX_V]; //??\?¬???°
    bool used[MAX_V];
    memset(indeg, 0, sizeof(indeg));
    memset(used, 0, sizeof(used));

    rep(i,v) rep(j,g[i].size()) indeg[ g[i][j] ]++;
    rep(i,v) if(indeg[i] == 0 && not used[i]) bfs(i, indeg, used);

    //for(auto it:tp) cout << it << endl;

    if(tp.size() == v) return false;
    else return true;
}

int main(){
    int v, e;
    cin >> v >> e;
    rep(i,e){
        int s, t;
        cin >> s >> t;
        g[s].emplace_back(t);
    }
    cout << topologicalSort(v) << endl;
}

Measured memory_bytes: 3444
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  for(int i = 9; i > 0; i--){
    if(n%i == 0 && n/i < 10){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}


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

int main(){
  string s;
  cin>>s;
  int isA = 0, isB = 0;
  for(char c : s){
    if(c=='A') isA = 1;
    if(c=='B') isB = 1;
   }
  if(isA && isB) cout<<"Yes";
  else cout<<"No";
  return 0;
}
       


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

int main(){
  int n,m;
  cin >> n >> m;
  // map<int,int> mp;
  vector<int> a[n];
  rep(i,m){
    int p;
    string s;
    cin >> p >> s;
    p--;
    if(s=="AC")a[p].push_back(1);
    else a[p].push_back(0);
  }
  int ans_1=0;
  int ans_0=0;
  rep(i,n){
    int t=0;
    rep(j,a[i].size()){
      if(a[i][j]==1){
        ans_1++;
        ans_0 += t;
        t = 0;
        break;
      }
      else t++;
    }
  }
  cout << ans_1 << ' ' << ans_0 << endl;
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll N, i, A[100001], ans=0;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> A[i];
    }

    if(N==1){
        cout << 1 << endl;
    }

    else{
        for(i=1; i<=N-1; i++){
            if(A[i]==A[i+1]){
                while(i<=N-1 && A[i]==A[i+1]){
                    i++;
                }
                //i--;
            }
            if(A[i] < A[i+1]){
                while(i<=N-1 && A[i] <= A[i+1]){
                    i++;
                }
                if(i==N-1 && A[i]>A[i+1]) ans++;
            }
            else{
                while(i<=N-1 && A[i] >= A[i+1]){
                    i++;
                }
                if(i==N-1 && A[i]<A[i+1]) ans++;
            }
            ans++;
        }

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

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define EPS 1e-10

using namespace std;
typedef long long int ll;

double add(double a, double b){
    if(abs(a+b)<EPS*(abs(a)+abs(b))) return 0;
    return a+b;
}
   
struct P{
    double x, y;
    P() {}
    P(double x, double y): x(x), y(y){
    }
    P operator+ (P p){
        return P(add(x, p.x), add(y, p.y));
    }
    P operator- (P p){
        return P(add(x, -p.x), add(y, -p.y));
    }
    P operator* (double d){
        return P(x*d, y*d);
    }
    double dot(P p){
        return add(x*p.x, y*p.y);
    }
    double det(P p){
        return add(x*p.y, -y*p.x);
    }
    bool operator< (const P& p) const{
        if(abs(x-p.x)>EPS){
            return x<p.x;
        }else{
            return y<p.y-EPS;
        }
    }
};

double dist(P p1, P p2){
  return sqrt((p1-p2).dot(p1-p2));
}

int main()
{
	P p[6];
  double r[6], a[6];
  for(int i=0; i<3; i++){
    double x, y;
    cin>>x>>y;
    p[i]=P(x, y);
    p[i+3]=p[i];
  }
  for(int i=0; i<3; i++){
    r[i]=dist(p[i+1], p[i+2]);
    r[i+3]=r[i];
  }
  for(int i=0; i<3; i++){
    a[i]=acos(((p[i+1]-p[i]).dot(p[i+2]-p[i]))/(r[i+1]*r[i+2]));
    a[i+3]=a[i];
  }
  double ans=0;
  for(int i=0; i<3; i++){
    ans=max(ans, r[i]/(2.0+1.0/(tan(a[i+1]/2.0))+1.0/(tan(a[i+2]/2.0))));
  }
  printf("%.10lf\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define P pair<int,int>
#define prique priority_queue
int sy,sx,ty,tx;
signed main(){
    cin>>sy>>sx>>ty>>tx;
    rep(i,tx-sx)cout<<"U";
    rep(i,ty-sy)cout<<"R";
    rep(i,tx-sx)cout<<"D";
    rep(i,ty-sy)cout<<"L";
    cout<<"L";
    rep(i,tx-sx+1)cout<<"U";
    rep(i,ty-sy+1)cout<<"R";
    cout<<"DR";
    rep(i,tx-sx+1)cout<<"D";
    rep(i,ty-sy+1)cout<<"L";
    cout<<"U"<<endl;
    return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, m;
vector<pair<int, int>> v[101010];
int p[101010], y[101010];
int a[101010], b[101010];

string fix(int n){
    int sz = d_cnt(n);
    return string(6 - sz, '0') + (string)to_string(n);
}

int main(){
    INIT;
    cin >> n >> m;
    REP(i, m){
        cin >> p[i] >> y[i];
        a[i] = p[i];
        v[p[i]].emplace_back(make_pair(y[i], i));
    }
    for(int i = 1;i <= n;i++){
        sort(ALL(v[i]));
        REP(j, (int)v[i].size()){
            b[v[i][j].second] = j + 1;
        }
    }
    REP(i, m){
        cout << fix(a[i]) << fix(b[i]) << endl;
    }
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // べき乗
  ll m, n; cin >> m >> n;
  ll MOD = 1e9 + 7;
  ll ans = 1, tmp = m;
  REP(i, 32){
    if((n >> i) & 1) ans = (ans * tmp) % MOD;
    tmp *= tmp;
    tmp %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3216
#include<iostream>
#include<string>

using namespace std;

int main(void){
	unsigned long long n, a, b, set, res;

	cin >> n >> a >> b;

	set = n / (a + b);
	res = set * a;
	n -= set * (a + b);
	if(n > a){
		res += a;
	}else{
		res += n;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
local n = io.read("n")
local m = io.read("n")
local mm = math.ceil(m ^ 0.5)
local max = 0
for i = 1, mm do
	if m % i == 0 then
		local a = i
		local b = m // a
		if b >= n then
			max = math.max(a, max)
		end
		if a >= n then
			max = math.max(b, max)
		end
	end
end
print(max)


Measured memory_bytes: 760
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;

int main() {
	ll N = 0, counter = 0;
	cin >> N;
	string S;
	cin >> S;
	rep(i, N-2) {
		if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') counter++;
	}
	cout << counter << endl;
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	int32 n, m, a;
	while(cin >> n >> m >> a){
		vector<int32> v(n);
		REP(i, n) v[i] = i+1;
		using T = tuple<int32, int32, int32>;
		vector<T> l(m);
		REP(i, m){
			int32 x, y, z;
			cin >> x >> y >> z; y--; z--;
			l.push_back(T(x, y, z));
		}
		sort(all(l), greater<T>());
		REP(j, m){
			swap(v[get<1>(l[j])], v[get<2>(l[j])]);
		}
		REP(i, n){
			if(v[i] == a){
				cout << i+1 << endl;
				break;
			}
		}
	}
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,q,h,w,t,ans=0;
vl v,v1,v2;
vp p;
string s;
priority_queue<ll> q1;
priority_queue<ll,vector<ll>,greater<ll>> q2;
ll solve(){
    ll dp[4000][4000];
    rep(i,m){
        rep(j,n){
            if(i==0&&j==0){
                if(v1[0]==v2[0])dp[0][0]=2;
                else dp[0][0]=1;
            }
            else if(j==0){
                if(v1[i]==v2[0])dp[i][0]=dp[i-1][0]+1;
                else dp[i][0]=dp[i-1][0];
            }
            else if(i==0){
            	if(v1[0]==v2[j])dp[0][j]=dp[0][j-1]+1;
                else dp[0][j]=dp[0][j-1];
            }
            else{
                if(v1[i]==v2[j])dp[i][j]=(dp[i][j-1]+dp[i-1][j])%MOD;
                else dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%MOD;
            }
            //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        }
    }
    return (dp[m-1][n-1]+MOD)%MOD;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>m>>n;
    rep(i,m){
        cin>>a;
        v1.push_back(a);
    }
    rep(i,n){
        cin>>a;
        v2.push_back(a);
    }
    cout<<solve()<<endl;
}

Measured memory_bytes: 64128
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

const int MOD = 1e9 + 7 , MAXN = 5e6 + 10;
int fac[MAXN] , finv[MAXN];
int f[2020][2020];
int n , k;
void init(){
	fac[0] = finv[0] = fac[1] = finv[1] = 1;
	for(int i = 2 ; i <= 5000000 ; ++ i)
		fac[i] = 1ll * i * fac[i - 1] % MOD;
	for(int i = 2 ; i <= 5000000 ; ++ i)
		finv[i] = MOD - 1ll * (MOD / i) * finv[MOD % i] % MOD;
	for(int i = 1 ; i <= 5000000 ; ++ i)
		finv[i] = 1ll * finv[i - 1] * finv[i] % MOD;
}
int C(int x , int y){
	return 1ll * fac[x] * finv[y] % MOD * finv[x - y] % MOD;
}
int main(){
	cin >> n >> k;
	if(k == 1){
		cout << 1 << endl;
		return 0;
	}
	init();
	f[0][0] = 1;
	for(int i = 1 ; i <= n ; ++ i){
		for(int j = 1 ; j < i ; ++ j)
			f[i - 1][j] = (f[i - 1][j] + f[i - 1][j - 1]) % MOD;
		for(int j = 0 ; j < i ; ++ j)
			f[i][j] = 1ll * f[i - 1][j] * C(i * (k - 1) + j - 1 , k - 2) % MOD;
	}
	int ans = 0;
	for(int i = 0 ; i < n ; ++ i)
		ans = (ans + f[n][i]) % MOD;
	cout << 1ll * ans * fac[n] % MOD << endl;
	return 0;
}

Measured memory_bytes: 54400
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cstring>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

const int INF = 1<<29;

int gcd(int m, int n){
	while(n){
		m%=n;
		swap(m, n);
	}
	return m;
}

int check(int n){
	int res = 0;
	for(int i = 2; i <= n; i++){
		for(int j = 1; j < i; j++){
			if(gcd(i,j) == 1){
				res++;
			}
		}
	}
	return res+2;
}

const int N = 1000001;

ll dp[N];
int isp[N];
int main(){
	dp[1] = 2;
	rep(i, N) isp[i] = true;
	isp[0] = isp[1] = false;

	for(int i = 2; i < N; i++){
		if(isp[i] > 0){
			for(int j = i*2; j < N; j+=i){
				isp[j]--;
				dp[j] -= (j/i-1);
			}
		}else if(isp[i] < 0){
			for(int j = i*2; j < N; j+=i){
				isp[j]++;
				dp[j] += (j/i-1);
			}
		}
	}

	for(int i = 1; i < N; i++){
		dp[i] += dp[i-1] + i - 1;
	}

	int T;
	cin >> T;
	while(T--){
		int n;
		cin >> n;
		cout << dp[n] << endl;
	}

	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main(void){
	string s;
	cin >> s;
	if(s.substr(0,4)=="YAKI")
		puts("Yes");
	else
		puts("No");
	
	return 0;
}

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

int main()
{
ll x , k ;
cin >> x >> k ;
vector<ll> r(k+1);
rep(i,k){
  cin >> r[i+1];
}
ll q ;
cin >> q ;
ll ans[q] = {};
pair<ll,ll> qq[q];
rep(i,q){
  ll t , a ;
  cin >> t >> a ;
  qq[i]={t,a};
}
ll itr=0;
ll mx=x,mi=0,c=0;
bool isdec=1;
rep(i,q){
  while(itr!=k && r[itr+1]<qq[i].first ){
    //更新
    if(isdec){
      c-=r[itr+1]-r[itr];
      if(-c>mi)mi=-c;
      if(mx<mi)mx=mi;
    }
    else{
      c+=r[itr+1]-r[itr];
      if(mx+c>x)mx=x-c;
      if(mx<mi)mi=mx;
    }
    isdec=!isdec;
    itr++;
  }
  ll te;
  if(qq[i].second>mx)te=mx+c;
  else if(qq[i].second<mi)te=mi+c;
  else te=qq[i].second+c;
  if(isdec)te-=qq[i].first-r[itr];
  else te+=qq[i].first-r[itr];
  if(te>x)te=x;
  else if(te<0)te=0;
  ans[i]=te;
}


rep(i,q)cout << ans[i] << endl;
return 0;
}

Measured memory_bytes: 4352
H,W=map(int,input().split())
N=int(input())
*A,=map(int,input().split())
A=[0]+A
ans=[[0]*W for _ in range(H)]
countH=0
countW=0
i=0
for a in A:
    for _ in range(a):
        ans[countH][countW]=str(i)
        if countW==W-1 and countH%2==0:
            countH+=1
        elif countW==0 and countH%2==1:
            countH+=1
        elif countH%2==0:
            countW+=1
        elif countH%2==1:
            countW-=1
    i+=1

for s in ans:
    print(*s)

Measured memory_bytes: 9520
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef queue<int> Q;

int main(){
    int n; cin>>n;
    V w(n);
    for(int i=0; i<n; i++){
        cin >> w[i];
    }
    int ans = 10000;
    for(int i=0; i<n; i++){
        int s1=0,s2=0;
        for(int j=0; j<n; j++){
            if(j<=i) s1 += w[j];
            else s2 += w[j];
        }
        ans = min(ans, abs(s1-s2));
    }
    OUT(ans);
}

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

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

  unordered_map<string, int> count;

  rep(i, n) {
    string s;
    cin >> s;

    if (count[s]) {
      count[s]++;
    } else {
      count[s] = 1;
    }
  }

  cout << count.size() << endl;

  return 0;
}


Measured memory_bytes: 17744