akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

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

vector<int> to[200005];
 vector<int> ans;


void dfs(int v, int p = -1){
    for(int u : to[v]){
        if(u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }

}

int main(){
    int n,q; cin >> n >> q;
    
    
    rep(i, n-1){
        int a,b; cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);

    }
    
    vector<int> p(q), x(q);
    ans.resize(n);
    rep(i,q){
        int p,x;
        cin >> p >> x;
        --p;
        ans[p] += x;
        
    }
    
    dfs(0);
    
    rep(i,n){
        cout << ans[i]<< endl;
    }
    
    return 0;


}


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

int main() {
  int x;
  cin >> x;
  if (x>=30) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int H, W;
vector<string> S;

int main(int argc, char const *argv[])
{
    cin >> H >> W;
    
    string in;
    for (int i = 0; i < H; i++)
    {
        cin >> in;
        S.emplace_back(in);
    }
    
    int pi[8] = {-1, -1,  0, +1, +1, +1,  0, -1};
    int pj[8] = { 0, -1, -1, -1,  0, +1, +1, +1};

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (S[i][j] == '#')
            {
                cout << "#";
            }else
            {
                int sum = 0;
                for (int k = 0; k < 8; k++)
                {
                    if (i + pi[k] < 0 || i + pi[k] > H - 1) continue;
                    if (j + pj[k] < 0 || j + pj[k] > W - 1) continue;

                    if (S[i + pi[k]][j + pj[k]] == '#')
                    {
                        sum++;
                    }
                    
                }
                cout << sum;
                
            }
            
        }
        cout << endl;
        
    }

    return 0;
}

Measured memory_bytes: 256
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]
ret = 1000000
for b in range(1 << d):
    s, n = 0, 0
    for i in range(d):
        if (b & (1 << i)) != 0:
            p = i * 100 + 100
            s += pc[i][0] * p + pc[i][1]
            n += pc[i][0]
    for i in range(d - 1, -1, -1):
        if (b & (1 << i)) == 0 and s < g:
            p = i * 100 + 100
            m = min((g - s + p - 1) // p, pc[i][0])
            s += m * p
            n += m
    if s >= g:
        ret = min(ret, n)
print(ret)


Measured memory_bytes: 41456
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

	vector<int> ans;
	ans.push_back(a[0]);
	for(int i=1;i<n;++i)
	{
		int left = -1,right=ans.size();
		while(1)
		{
			ll mid = ((1LL)*left + (1LL)*right)/2;
			if(a[i]<=ans[mid])left=mid;
			else right = mid;
			if(right-left==1)
			{
				if(right==ans.size())
				{
					ans.push_back(a[i]);
				}
				else
				{
					ans[right]=a[i];
				}
				break;
			}
			
			
		}
		//rep(i,ans.size())cout<<ans[i]<<" ";cout<<endl;
	}
	
	cout<<ans.size()<<endl;

	return 0;
}

Measured memory_bytes: 1276
import math
from collections import defaultdict


def SieveofEratosthenes(N):
    if N < 2:
        raise ValueError('N should be more than 2')
    primeList = []
    limit = math.sqrt(N)
    data = [i + 1 for i in range(1, N)]
    while True:
        p = data[0]
        if limit <= p:
            return primeList + data
        primeList.append(p)
        data = [e for e in data if e % p != 0]


Q = int(input())
primeList = SieveofEratosthenes(10**5)
primeDict = defaultdict(int)
like2017Dict = defaultdict(int)
for p in primeList:
    primeDict[p] = 1
for p in primeList:
    if primeDict[(p+1)//2] == 1:
        like2017Dict[p] = 1

numPrimes = [0 for i in range(10**5+1)]
for i in range(3, 10**5+1):
    if like2017Dict[i] == 1:
        numPrimes[i] = numPrimes[i-1] + 1
    else:
        numPrimes[i] = numPrimes[i-1]


def solve(l, r):
    ans = numPrimes[r] - numPrimes[l-1]
    return ans


for i in range(Q):
    l, r = map(int, input().split())
    print(solve(l, r))

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

int main() {
  int N, sum = 0;
cin >> N; 
  vector<int> C(N), V(N);
  
  for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (C.at(i) < V.at(i)) {
      sum += V.at(i) - C.at(i);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
program nikkei20192qualb
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i
    integer(int64), allocatable:: d(:),cnt(:),ans
    integer(int64), parameter:: md = 998244353

    read*, n
    allocate(d(n))
    read*, d(:)
    if (d(1) /= 0) then
        print'(i0)', 0
        stop
    end if
    allocate(cnt(0:maxval(d)))
    cnt(:) = 0
    cnt(0)=1
    do i=2,n
        cnt(d(i))=cnt(d(i))+1
    end do

    if (cnt(0) > 1) then
        print'(i0)', 0
        stop
    end if

    if (minval(cnt) == 0) then
        print'(i0)', 0
        stop
    end if

    ans=1
    do i=1,size(cnt)-1
        ans = mod(ans*factorial(cnt(i-1),cnt(i),md),md)
    end do
    print'(i0)', ans


contains
    function factorial(a,b,md) result(ret)
        integer(int64):: a,b,md
        integer(int64):: aa,bb,ret
        aa = a
        bb = b
        ret = 1
        do while(bb > 0)
            if (mod(bb,2_8)/=0) ret=mod(ret*aa,md)
            aa=mod(aa*aa,md)
            bb=bb/2
        end do
    end function
    
end program nikkei20192qualb

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 410000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
//invの要素にはiの逆元が格納されている
//前処理
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;//i!(mod MOD)を計算
        inv[i] = MOD - inv[MOD%i]* (MOD / i) % MOD;//iの逆元を計算
        finv[i] = finv[i - 1] * inv[i] % MOD;//i!(mod 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;//nCk = n!/(k!*(n-k)!)を計算
}
int main(){
    int N, K;
    cin >> N >> K;
    COMinit();
    for(int i = 1; i < K + 1; i++){
        cout << COM(N - K + 1, i) * COM(K - 1, i - 1) % MOD << endl;
    }
}

Measured memory_bytes: 13240
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	val (a,v) = f.readLine().split(" ").map{it.toLong()}
	val (b,w) = f.readLine().split(" ").map{it.toLong()}
	val t = f.readLine().toLong()

	if(a == b){
		println("YES")
	} else if(w >= v){
		println("NO")
	} else {
		val gain : Long = t*v - t*w
		if(abs(a-b) <= gain){
			println("YES")
		} else {
			println("NO")
		}
	}
}


Measured memory_bytes: 36388
#include<stdio.h>
int main(void)
{
  int x,y;
  int flag=1;
  while(flag=1){
    scanf("%d %d",&x,&y);
    if((x==0)&&(y==0)){
      flag=0;
      break;
    }else if(x>y){
      int num;
      num=x;
      x=y;
      y=num;
      printf("%d %d\n",x,y);
    }else if(x<=y){
      printf("%d %d\n",x,y);
    }
  }
  return 0;
}
    


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

int main()
{
    ll a, b, k;
    cin >> a >> b >> k;

    if (k <= a)
        cout << a - k << " " << b << endl;
    else
        cout << 0 << " " << max(ll(0), b - k + a) << endl;
}

Measured memory_bytes: 3672
/*
 * @Author: AsilenceBTF
 * @Buff: ︿(￣︶￣)︿  芜湖塔台 起飞
 * @Date: 2019-06-20 09:22:24
 * @LastEditTime: 2020-09-21 20:39:52
 */
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define ALL(x) x.begin(), x.end()
#define INF 0x3f3f3f3f
#define debug(x) cout << "##### " << x << endl; 
typedef long long ll;

// #define cin in
// #define cout out
// ifstream in("in.txt");
// ofstream out("out.txt");

const int N = 2e5 + 105;

ll pre[N], a[N], idx[N];
int main(){
    ll n, x, m;
    cin >> n >> x >> m;
    for(int i = 1; i < N; ++i){
        a[i] = x;
        pre[i] = pre[i - 1] + a[i];
        x = x * x % m;
    }
    if(n < N) cout << pre[n] << endl;
    else{
        ll ans = 0, l = 0, r = 0;
        for(int i = 1; i < N; ++i){
            if(idx[a[i]]){
                l = idx[a[i]], r = i - 1;
                break;
            }
            idx[a[i]] = i;
            --n;
            ans += a[i];
        }
        ans += (pre[r] - pre[l - 1]) * (n / (r - l + 1));
        n %= (r - l + 1);
        for(int i = r + 1; i < N; ++i){
            if(n <= 0) break;
            ans += a[i];
            --n;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 7512
# https://atcoder.jp/contests/abc070/tasks/abc070_c
# C - Multiple Clocks
import fractions

n = int(input().split()[0])
t_list = []

for _ in range(n):
    t_list.append(int(input().split()[0]))

t_list = list(set(t_list))
a = t_list[0]

for t in t_list[1:]:
    a = a * t // fractions.gcd(a, t)

print(a)


Measured memory_bytes: 5048
h, w = map(int, input().split())

s = [input() for _ in range(h)]
ans = ['' for _ in range(h)]

for y in range(h):
    for x in range(w):
        if s[y][x] == '.':
            cnt = 0
            for dy in range(-1, 2, 1):
                for dx in range(-1, 2, 1):
                    if 0 <= x+dx < w and 0 <= y+dy < h:
                        if s[y+dy][x+dx] == '#':
                            cnt += 1
            ans[y] += str(cnt)
        else:
            ans[y] += '#'

for t in ans:
    print(t)

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

int N, Q, s[1000000];
vector< int > Student;
multiset< int > Leader;

bool Check(int value, int x)
{
  vector< int >::iterator last = Student.begin();
  int Lost = 0;
  for(multiset< int >::iterator it = Leader.begin(); it != Leader.end() && last != Student.end(); ++it) {
    Lost += lower_bound(last, Student.end(), *it - value) - last;
    last = upper_bound(last, Student.end(), *it);
  }
  Lost += Student.end() - last;
  return(Lost <= x);
}
int BinarySearch(int Lower, int Upper, int x)
{
  int Mid = (Lower + Upper) >> 1;
  if(Lower >= Upper) return(Lower);
  if(Check(Mid, x)) return(BinarySearch(Lower, Mid, x));
  return(BinarySearch(Mid + 1, Upper, x));
}
main()
{
  cin >> N >> Q;
  Student.resize(N);
  for(int i = 0; i < N; ++i) {
    cin >> Student[i];
    s[i] = Student[i];
  }
  sort(Student.begin(), Student.end());
  while(Q--) {
    string Query;
    int a;
    cin >> Query >> a;
    if(Query[0] == 'A') { // "ADD"
      Leader.insert(s[--a]);
    } else if(Query[0] == 'R') { // "REMOVE"
      Leader.erase(Leader.find(s[--a]));
    } else { // "CHECK"
      int ret = BinarySearch(0, 1 << 30, a);
      if(ret == 1 << 30) cout << "NA" << endl;
      else cout << ret << endl;
    }
  }
}

Measured memory_bytes: 8928
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int maxN = 87;
int32_t main(){
    SPEED;
    int h, w;
    cin >> h >> w;
    h += 2;
    w += 2;
    char mat[h][w];
    for(int i = 1; i < h - 1; ++i){
        for(int j = 1; j < w - 1; ++j){
            cin >> mat[i][j];
        }
    }
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(i == 0 || i == h - 1 || j == 0 || j == w - 1) cout << '#';
            else cout << mat[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

void seq(vector<vector<ll>> &next, vector<ll> &cnt, ll from, ll ff) {
  for (ll i = 0; i < next.at(from).size(); i++) {
    if (from != 0 && next.at(from).at(i) - 1 == ff) continue;
    cnt.at(next.at(from).at(i) - 1) += cnt.at(from);
    seq(next, cnt, next.at(from).at(i) - 1, from);
  }
  return;
}

int main() {
  ll n, q, a, b;
  cin >> n >> q;
  vector<vector<ll>> next(n, vector<ll>(0));
  for (ll i = 0; i < n - 1; i++) {
    cin >> a >> b;
    next.at(a - 1).push_back(b);
    next.at(b - 1).push_back(a);
  }
  vector<ll> p(q), x(q), cnt(n, 0);
  for (int i = 0; i < q; i++) {
    cin >> p.at(i) >> x.at(i);
    cnt.at(p.at(i) - 1) += x.at(i);
  }
  seq(next, cnt, 0, 0);
  for (ll i = 0; i < n - 1; i++) cout << cnt.at(i) << " ";
  cout << cnt.at(n - 1) << endl;
}

Measured memory_bytes: 36736
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static final int INF = 1000000000;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int[][] cost = new int[100][100];
		int[][] time = new int[100][100];
		
		while(true){
			int n = Integer.parseInt(sc.next());
			int m = Integer.parseInt(sc.next());
			if(n == 0 && m == 0){
				break;
			}
			
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					cost[i][j] = INF;
					time[i][j] = INF;
				}
			}
			for(int i = 0; i < n; i++){
				int a = Integer.parseInt(sc.next()) - 1;
				int b = Integer.parseInt(sc.next()) - 1;
				cost[a][b] = Integer.parseInt(sc.next());
				cost[b][a] = cost[a][b];
				time[a][b] = Integer.parseInt(sc.next());
				time[b][a] = time[a][b];
			}
			for(int k = 0; k < m; k++){
				for(int i = 0; i < m; i++){
					for(int j = i + 1; j < m; j++){
						cost[i][j] = Math.min(cost[i][j], cost[i][k] + cost[k][j]);
						cost[j][i] = cost[i][j];
						time[i][j] = Math.min(time[i][j], time[i][k] + time[k][j]);
						time[j][i] = time[i][j];
					}
				}
			}
			int k = sc.nextInt();
			PrintWriter out = new PrintWriter(System.out);
			for(int i = 0; i < k; i++){
				int p = Integer.parseInt(sc.next()) - 1;
				int q = Integer.parseInt(sc.next()) - 1;
				int r = Integer.parseInt(sc.next());
				if(r == 0){
					out.println(cost[p][q]);
				}else if(r == 1){
					out.println(time[p][q]);
				}
				out.flush();
			}
		}
		
		sc.close();
	}

}

Measured memory_bytes: 76900
#include<iostream>
using namespace std;
struct P{
  double x;
  double y;
};
int main(){
  P a,b,c,d;
  while(cin >>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y){
    if(c.x<=b.x && a.x<=d.x && c.y<=b.y && a.y<=d.y) cout <<"YES"<<endl;
    else cout <<"NO"<<endl;
  }
  return 0;
}

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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int a, b;
  cin >> a >> b;
  cout << a * b << "\n";
}

Measured memory_bytes: 3648
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        do_(inp);
        inp.close();
    }
    public static void do_(Scanner inp) {
        int a = inp.nextInt();
        int b = inp.nextInt();
        int ans = a * (a - 1) / 2 + b * (b - 1) / 2;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N, x;
  std::cin >> N >> x;
  std::vector<i64> a;
  tools::read(a, N);

  // dp[i][j] ... 魔法をj回使う場合の、色i(0-based indexing)のスライムの素材になるスライムを捕獲するのにかかる最低時間
  std::vector<std::vector<i64>> dp(N, std::vector<i64>(N));
  for (i64 i = 0; i < N; ++i) {
    dp[i][0] = a[i];
    for (i64 j = 1; j < N; ++j) {
      dp[i][j] = std::min(dp[i][j - 1], a[(i - j + N) % N]);
    }
  }

  i64 answer = std::numeric_limits<i64>::max();
  for (i64 j = 0; j < N; ++j) {
    i64 possible_answer = 0;
    for (i64 i = 0; i < N; ++i) {
      possible_answer += dp[i][j];
    }
    possible_answer += x * j;
    answer = std::min(answer, possible_answer);
  }

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

Measured memory_bytes: 31744
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
#define rep2(i,n) for(int i = 1; i <= (int) n; i++)
int main(void) {
  int n,m;
  cin >> n >> m;
  vector<int> h(m * 2);
  rep(i,m * 2){
    cin >> h.at(i);
  }

  vector<int> ans(n+5,0);
  rep2(j,n){
    rep(i,m * 2){
      if(h.at(i) == j){
        ans.at(j)++;
      }
    }
  }
  rep2(i,n){
    cout << ans.at(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
from collections import defaultdict
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def prime_factorize(n): # Nの素因数分解
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

# 約数の組み合わせ（３・５・５）（７５）など
N = ir()
dic = defaultdict(int)
for x in range(2, N+1):
    primes = prime_factorize(x)
    for p in primes:
        if p in dic:
            dic[p] += 1
        else:
            dic[p] = 1

answer = 0
for x, y, z in itertools.permutations(dic.values(), 3):
    if x >= 2 and y >= 4 and z >= 4:
        answer += 1

answer //= 2
for x, y in itertools.permutations(dic.values(), 2):
    if x >= 4 and y >= 14:
        answer += 1
    if x >= 2 and y >= 24:
        answer += 1

for x in dic.values():
    if x >= 74:
        answer += 1

print(answer)
# 40

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

using namespace std;

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

int main(){
    int a,b,c;cin>>a>>b>>c;
    if(a==b){
        cout<<c<<endl;
    }else if(a==c){
        cout<<b<<endl;
    }else{
        cout<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

void showes(vector<char> ans) {
  for (auto itr : ans) {
    cout << itr;
  } END;
}

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  vector<char> applyed(2);
  applyed[0] = 'S';
  applyed[1] = 'W';
  s.pb(s[0]);
  s.pb(s[1]);

  for (int bit = 0; bit < (1 << 2); ++bit) {
    // 0 -> 羊, 1 -> 狼
    vector<int> now(n+2);
    vector<char> ans(n+2);
    for (int j = 0; j < 2; ++j) {
      now[j] = (bit >> j) & 1;
      ans[j] = applyed[now[j]];
    }

    int last = now.front();
    for (int i = 1; i <= n; ++i) {
      if (now[i] == 0) {
        // 羊 phase
        if (s[i] == 'o') {
          now[i+1] = now[i-1];
        } else {
          now[i+1] = (now[i-1] == 0) ? 1 : 0;
        }
      } else {
        // 狼 phase
        if (s[i] == 'o') {
          now[i+1] = (now[i-1] == 0) ? 1 : 0;
        } else {
          now[i+1] = now[i-1];
        }
      }
      ans[i+1] = applyed[now[i+1]];
    }
    if (now[n+1] == now[1] and now[0] == now[n]) {
      ans.pop_back();
      ans.pop_back();
      showes(ans);
      return 0;
    }
  }

  cout << -1 << endl;
}


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

int main(){

	string str;
	cin >> str;

	int n ;
	cin >> n;

	for(int i=0; i<n;i++){
//		命令
		string order;
		cin >> order;
		int a,b;
		if(order == "replace"){
			string c;
			cin >> a >> b >> c;
			string d ="";
			for(int o=0;o<str.length();o++){
				if(o >=a && o <b){

				}else if(o == b){
					d += c;
				}else{
					d += str[o];
				}
			}
			str = d;
			//cout << str <<" " << str.length() <<" ";

		}else if(order == "reverse"){
			cin >> a >> b;
			string d = "",e = "";
			for(int p=0;p<str.length();p++){
				if(p >=a && p <b){
					e += str[p];
				}else if(p == b){
					e += str[p];

					string f = "";
					for(int k = e.length()-1;k >= 0;k--){
						f += e[k];
					}
					d += f;
				}else{
					d += str[p];
				}
			}
			str = d;
			//cout << str <<" "<< str.length() <<" ";
		}else if(order == "print"){
			cin >>a>>b;
			for( ; a <= b ;a++)
				cout << str[a];
			cout << endl;
		}

	}

	return 0;
}


Measured memory_bytes: 3204
def accumulate(a, b):
    k = b - a + 1
    return k * (k+1) // 2 + k * (a-1)

def solve(n, a, b):
    if b < a:
        return 0
    if n == 1:
        if a == b:
            return 1
        else:
            return 0
    else:
        return (b - a) * (n - 2) + 1

n, a, b = map(int, input().split())
print(solve(n, a, b))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;

int main(void){
	int a,b;
  cin>>a>>b;
  if(a>12){
    cout<<b<<endl;
  }
  else if(a>5){
	cout<<b/2<<endl;
  }
  else{
	cout<<0<<endl;
  }
  
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	vvi f(n,vi(m));
	int q;cin>>q;
	vi in(q);
	rep(i,q)cin>>in[i];
	int x=0,y=0;
	rep(i,q)while(in[i]){
		f[x][y]=i+1;
		if(y%2==0)x++;
		else x--;
		if(x==-1){
			x=0;y++;
		}else if(x==n){
			x=n-1;y++;
		}
		in[i]--;
	}
	rep(i,n){rep(j,m)cout<<(j?" ":"")<<f[i][j];cout<<endl;}
}







Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define testfor(T) ll T; cin>>T; while(T--)
using namespace std;
int main(){
	int a;cin>>a;
	int sq = a*a;
	int thr = a*a*a;
	cout<<a+sq+thr<<"\n";
}

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

public class Main{

	public static void main(String args[]){
		new Main().mainrun();
	}

	private Scanner scan;
	int max = 100000000;

	boolean[] Prime = new boolean[max];
	private void mainrun() {
		scan = new Scanner(System.in);
		Arrays.fill(Prime, true);

		Prime[0] = Prime[1] = false;
		
		for(int i = 2;i < Math.sqrt(max);i++) {
			if(Prime[i]) {
				for(int j = i * 2;j < max;j += i) {
					Prime[j] = false;
				}
			}
		}

		for(int N = scan.nextInt();N != 0;N = scan.nextInt()){
			int Ans = 0;
			int count = N;
			for(int i = 2; i < max && count != 0;i ++) {
				if(Prime[i]) {
					Ans +=i ;
					count--;
				}
			}
			System.out.println(Ans);
		}

	}
}


Measured memory_bytes: 124940
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for1(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rfor1(i, a, b) for (int i=b-1;i>=a;i--)
#define for2(i, a, b) for (int i = (int)a; i <= (int)(b); ++i)
#define for3(i, a, b) for (int i = (int)a; i < (int)(b); i=i+2)
#define for4(i, a, b) for (int i = (int)a; i <= (int)(b); i=i+2)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
//==================================================================//

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
//=================================================================//
	int x, y;
	cin >> x >> y;
	cout << x + y / 2 << endl;



}








Measured memory_bytes: 3600
x = input()
y = input()
 
if len(x) > 10:
  print('No')
elif len(y) - len(x) != 1:
  print('No')
elif x.islower() ==False or x.isalpha() != True:
  print('No')
elif x != y[:-1]:
  print('No')
else:
  print('Yes')

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

using namespace std;

const int N=1e6+10;

int n,a[N];
int main(){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        int suma=0,sumx=0;
        long long ans=0;
        for(int st=1,en=1;st<=n;st++){
                while (en<=n&&suma+a[en]==(sumx^a[en])){
                        suma+=a[en];
                        sumx^=a[en];
                        en++;
                }
                ans+=en-st;
                suma-=a[st];
                sumx^=a[st];
        }
        cout<<ans;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long int 
    vector<ll>v[200005];
    ll ans[200005];
    void solve(ll Node,ll parent)
    {
        ll i=0;
        for( i=0;i<v[Node].size();i++)
        {
            if(v[Node][i]==parent)
            continue;
            else
            {
                ans[v[Node][i]]+=ans[Node];
                solve(v[Node][i],Node);
            }  
        }
        return;
    }
    int main()
    {
        ll a,b,n,q,i,M=1,N=1;
        cin>>n>>q;
        for(i=0;i<n-1;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }
        for(i=0;i<q;i++)
        {
            cin>>a>>b;
            ans[a]+=b;
        }
        solve(M,N);
        for(i=1;i<=n;i++)
        cout<<ans[i]<<" ";
    } 

Measured memory_bytes: 24320
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    FOR(i, 0, n)cin >> a[i].first >> a[i].second;
    rSORT(a, [](auto a, auto b) {return a.second < b.second; });

    int now = 0;
    FOR(i, 0, n) {
        now += a[i].first;
        if (now > a[i].second) {
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
}

Measured memory_bytes: 1792
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
        where <T as FromStr>::Err: Debug
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let xy: Vec<i64> = util::gets();

    match (xy[0] - xy[1]).abs() {
        0 => println!("Brown"),
        1 => println!("Brown"),
        _ => println!("Alice"),
    }
}


Measured memory_bytes: 4352
n = int(input())
aa = [0]*n
bb = [0]*n
for i in range(n):
    aa[i],bb[i] = map(int, input().split())
ans = 0
for i in range(1,n+1):
    cnt = 0
    cur = aa[-i] + ans
    if cur % bb[-i] > 0:
        cnt = ((cur - 1) // bb[-i] +1) * bb[-i] - cur
        # print(cur, bb[-i], cnt, aa)
        ans += cnt
    
print(ans)

Measured memory_bytes: 10868
def main():
    N, A, B = map(int, input().split())
    if A > B: return 0
    if N == 1 and A !=B: return 0

    maxv = B*(N-1) + A
    minv = A*(N-1) + B
    return maxv - minv + 1

if __name__ == '__main__':
    print(main())

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  ll k; cin >> k;
  long double emax = 0;
  vector<long double> v(n); cin >> v;
  for(auto e:v){
    emax = max(emax,e);
  }
  long double l = 0.1,r = emax;
  for(int i = 0; i < 250; ++i){
    if(ceil(l) == ceil(r))break;
    if(l + 0.0000000001 >= r)break;
    long double mid = (l + r)/2;
    bool f = true;
    ll cnt = 0;
    for(auto e:v){
      //      cerr << e << ' ' << mid << ' ' << ceil(e/mid) << endl;
      cnt += ceil(e/mid)==floor(e/mid)?floor(e/mid)-1:floor(e/mid);
      if(cnt > k){
	f = false;
	break;
      }
    }
    if(!f)l = mid;
    else r = mid;
    //    exit(1);
  }
  cout << (int)ceil(r) << endl;
  return 0;
}


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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;


signed main(){

	int A, B, a, b;
	cin >> A >> B >> a >> b;

	cout << (A - a)*(B - b) << endl;


	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    print(180*(n-2))
    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()
    return

#D
def D():
    n = I()
    return

#E
def E():
    n = I()
    return

#F
def F():
    n = I()
    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 39152
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;



int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  string S;
  cin >> S;
  int st = -1;
  for (int i = 0; i < sz(S);i++) {
    if (S[i] == 'A') {
      st = i;
      break;
    }
  }
  int ed = -1;
  for (int i = sz(S)-1;i >= 0; i--) {
    if (S[i] == 'Z') {
      ed = i;
      break;
    }
  }
  assert(st != -1 && ed != -1);
  cout << ed - st + 1<< endl;
  return 0;
}



Measured memory_bytes: 720
#include <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	if (N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9) printf("hon\n");
	else if (N % 10 == 3) printf("bon\n");
	else printf("pon\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1624
n=int(input())
l=list(map(int,input().split()))
res=0
if(n<2):
    print(0)
else:
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                if(l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i]):
                    if(l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[k]+l[i]>l[j]):
                        res+=1
    print(res)


Measured memory_bytes: 68196
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<cmath>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(min(b,d)-max(a,c)>=0)
	{
		cout<<min(b,d)-max(a,c)<<endl;
	}
	else
	{
		cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
ll modi(ll a,ll m){
  ll b=m,u=1,v=0;
  while(b){
    ll t=a/b;
    a-=t*b;
    swap(a,b);
    u-=t*v;
    swap(u,v);
  }
  u%=m;
  if(u<0) u+=m;
  return u;
}
ll modp(ll a,ll b,ll m){
  if(b==0) return 1;
  if(b%2) return modp(a,b-1,m)*a%m;
  return modp(a,b/2,m)*modp(a,b/2,m)%m;
}
int main(){
  int Q;
  cin>>Q;
  vector<int> X(Q),D(Q),N(Q);
  rep(i,Q) cin>>X[i]>>D[i]>>N[i];
  int mod=1000003;
  vector<ll> A(mod);
  A[0]=1;
  rep(i,mod) if(i) A[i]=A[i-1]*i%mod;
  ll ans;
  rep(i,Q){
    if(D[i]){
      ll B=(X[i]*modi(D[i],mod)+N[i]-1)%mod;
      if(B<0) B+=mod;
      ll C=(X[i]*modi(D[i],mod)-1)%mod;
      if(C<0) C+=mod;
      if(N[i]>=mod||B%mod<=C%mod) ans=0;
      else{
        ans=A[B]*modi(A[C],mod)%mod;
        ans=ans*modp(D[i],N[i],mod)%mod;
        if(ans<0) ans+=mod;
      }
      cout<<ans<<endl;
    }else{
      ans=modp(X[i],N[i],mod)%mod;
      if(ans<0) ans+=mod;
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 9984
// 1222
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    string s; cin >> s;
    int a = 0, z = 0;
    For(i, 0, s.size()) {
        if(s[i] == 'A') {
            a = i;
            break;
        }
    }
    for(int i = s.size()-1; i >= 0; i--) {
        if(s[i] == 'Z') {
            z = i;
            break;
        }
    }

    //cout << z - a + 1;
    //cout << z << " " << a << endl;
    if(z - a > 0)  cout << z-a+1;
    else cout << 0;
    
    
    
    
    return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n;i++)
#define INF 100000000
#define SIZE 21
using namespace std;

int p,q;

int main(){
	while(cin>>p>>q,p||q){
		string P[10],Q[10];
		int ans[100];
		rep(i,100)ans[i]=INF;
		rep(i,p)cin>>P[i];
		rep(i,q)cin>>Q[i];
		Rep(R,SIZE)Rep(C,SIZE)Rep(S,SIZE){
			bool ok=true;
			int r=0,c=0,s=0;
			rep(i,p){
				bool check=true;
				int cnt=0;
				rep(j,P[i].size()){
					if(check&&P[i][j]=='.'){
						cnt++;
						continue;
					}
					if(P[i][j]!='.'&&check){
						if(r*R+c*C+s*S!=cnt){
							ok=false;
						}
						check=false;
					}
					if(P[i][j]=='(')r++;
					if(P[i][j]==')')r--;
					if(P[i][j]=='[')c++;
					if(P[i][j]==']')c--;
					if(P[i][j]=='{')s++;
					if(P[i][j]=='}')s--;
				}
			}
			if(!ok)continue;
			r=0;c=0;s=0;
			rep(i,q){
				if(ans[i]==INF)ans[i]=r*R+c*C+s*S;
				else if(ans[i]!=r*R+c*C+s*S) ans[i]=-1;
				rep(j,Q[i].size()){
					if(Q[i][j]=='(')r++;
					if(Q[i][j]==')')r--;
					if(Q[i][j]=='[')c++;
					if(Q[i][j]==']')c--;
					if(Q[i][j]=='{')s++;
					if(Q[i][j]=='}')s--;
				}
			}
		}
		rep(i,q){
			if(i)cout<<" ";
			cout<<ans[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin>>n;
  vector<ll> vec;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      vec.emplace_back(i+n/i-2);
    }
  }
  sort(vec.begin(),vec.end());
  cout<<vec[0]<<endl;  
}

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

int n, W;
int weight[110], value[110];
int dp[110][10010];

int main() {
	cin >> n >> W;
	for (int i = 0; i < n; ++i) cin >> value[i] >> weight[i];

	memset(dp, 0, sizeof(dp));

	for (int i = 0; i < n; ++i) {
		for (int w = 0; w <= W; ++w) {
			if (w >= weight[i]) dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w]);
			else dp[i + 1][w] = dp[i][w];
		}
	}
	cout << dp[n][W] << endl;
	return 0;
}


Measured memory_bytes: 7408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() { 
	string s; cin >> s;
	char next = '0'; int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != next) {
			ans++;
		}
		if (next == '0') {
			next = '1';
		}
		else {
			next = '0';
		}
	}
	int t = 0;
	next = '1';
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != next) {
			t++;
		}
		if (next == '0') {
			next = '1';
		}
		else {
			next = '0';
		}
	}
	cout << min(t, ans) << endl;
	return 0;
}

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

int main(){
	int64_t n, m;
	cin >> n >> m;
	int64_t a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	int64_t puni[m + 2]{}, muni[m + 2]{};
	for(int i = 0; i < n - 1; i++){
		int64_t s = a[i], t = a[i + 1];
		if(s == t) continue;
		if(s < t){
			muni[1] += t - s;
			muni[s + 1] += -(t - s);
			puni[s + 1] += -1;
			puni[t + 1] += 1;
			muni[s + 1] += 1 + t;
			muni[t + 1] += -(1 + t);
			muni[t + 1] += t - s;
			muni[m + 1] += -(t - s);
		}else{
			puni[1] += -1;
			puni[t + 1] += 1;
			muni[1] += 1 + t;
			muni[t + 1] += -(1 + t);
			muni[t + 1] += m - s + t;
			muni[s + 1] += -(m - s + t);
			puni[s + 1] += -1;
			puni[m + 1] += 1;
			muni[s + 1] += 1 + m + t;
			muni[m + 1] += -(1 + m + t);
		}
	}
	for(int i = 1; i < m + 2; i++){
		puni[i] += puni[i - 1];
		muni[i] += muni[i - 1];
	}
	for(int i = 0; i < m + 2; i++) cerr << puni[i] << ' ';
	cerr << endl;
	for(int i = 0; i < m + 2; i++) cerr << muni[i] << ' ';
	cerr << endl;
	int64_t ans[m + 2];
	for(int64_t x = 0; x < m + 2; x++) ans[x] = puni[x] * x + muni[x];
	for(int i = 0; i < m + 2; i++) cerr << ans[i] << ' ';
	cerr << endl;
	cout << *min_element(ans + 1, ans + m + 1) << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<int> data(N);
  long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
    sum += data.at(i);
  }
  long x = 0, y = sum, ans = 10000000000,a = 0;
  for (int i = 0; i < N - 1; i++) {
    y -= data.at(i);
    x = sum - y;
    a = abs(x - y);
    if (ans > a) ans = a;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main(){
    ll k; cin>>k;
    ll res=0;
    for(ll a=1; a<=k; a++){
        for(ll b=1; b<=k; b++){
            for(ll c=1; c<=k; c++){
                ll tmp=gcd(a,b);
                tmp=gcd(tmp,c);
                res+=tmp;
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 3e5+10;
const ll mod =   1e9+7;
ll z,n;
map<pair<ll,ll> , pair<ll,ll > > mp;
ll po(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=res*a%mod;
		b/=2;
		a=a*a%mod;
	}return res;
}
int main()
{  fast
cin>>n;
for(int i=0;i<n;i++)
{
	ll a,b;
	cin>>a>>b;
	if(a==0)
	{
		if(b==0)
		z++;
		else
		mp[{0,0}].fi++;
	}
	else if(!b)
	mp[{0,0}].se++;
	else
	{
	
		ll neg=0;
		if(a<0)
		{
			neg^=1;a=-a;
		}
		if(b<0)
		{
			neg^=1;b=-b;
		}	ll x=__gcd(a,b);
		a/=x;b/=x;
		if(neg)
		mp[{a,b}].se++;
		else
		mp[{b,a}].fi++;
	}
}
ll ans=1;
for(auto it : mp)
{

	ll x=it.se.fi;
	ll y=it.se.se;
	(ans*=(po(2,x)+po(2,y)-1+mod)%mod)%=mod;
}
//cout<<ans<<endl;
(ans+=z-1+mod)%=mod;
cout<<ans;


}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,R,C;

int main()
{
	scanf("%d%d%d",&R,&C,&N);
	vector< pair<int,int> > v [4];
	map<int,int> mp;
	FOR(i,0,N) FOR(j,0,2){
		int x,y;
		scanf("%d%d",&x,&y);
		if(x == 0){
			v [0].push_back(make_pair(y,i));
			mp [i]++;
		}
		else if(y == C){
			v [1].push_back(make_pair(x,i));
			mp [i]++;
		}
		else if(x == R){
			v [2].push_back(make_pair(-y,i));
			mp [i]++;
		}
		else if(y == 0){
			v [3].push_back(make_pair(-x,i));
			mp [i]++;
		}
	}
	FOR(i,0,4) sort(v [i].begin(),v [i].end());
	vector<int> w;
	FOR(i,0,4) FOR(j,0,v [i].size()) if(mp [v [i] [j].second] == 2){
		w.push_back(v [i] [j].second);
	}

	stack<int> st;
	FOR(i,0,w.size()){
		if(st.empty() || st.top() != w [i]){
			st.push(w [i]);
		}
		else{
			st.pop();
		}
	}

	puts(st.empty() ? "YES" : "NO");

	return 0;
}


Measured memory_bytes: 8040
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

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

int main(){
    int n;
    scanf("%d",&n);
    char ss[15]={};
    long long int a=0;
    long long int b=0;
    long long int ab=0;
    long long int aandb=0;
    REP(i,n){
        scanf("%s",ss);
        std::string str=ss;
        int abab=-1;
        while((abab=(int)str.find("AB",abab+1))!=-1){
            ab++;
            //printf("###%d\n",abab);
        }
        if(str[0]=='B'&&str[str.size()-1]=='A')aandb++;
        else if(str[0]=='B')b++;
        else if(str[str.size()-1]=='A')a++;
    }
    int min;
    if(a>b)min=b;
    else min=a;
    if(a==0&&b==0&&aandb>0)min-=1;
    //printf("%lld %lld %lld %lld\n",a,b,aandb,ab);
    printf("%lld\n",min+aandb+ab);
    return 0;
}

Measured memory_bytes: 256