akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, m, n) for(ll i = (ll)m; i < (ll)n; i++)
#define PER(i, m, n) for(ll i = (ll)m; i > (ll)n; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main(){
    ll row, column;
    cin >> row >> column;
    ll ans = 0;
    ll n = min(row, column);
    ll m = max(row, column);

    if(n == 1 && m == 1) ans = 1;
    else if(n == 1) ans = m-2;
    else ans = (n-2)*(m-2);
    cout << ans << endl;
}


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

using namespace std;

#define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t;
	t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}

int n, m;
const int N = 5000;
int a[N], b[N];
int ans_ending_here[N] = {0};
int new_ending_here[N] = {0};
const int M = 1e9 + 7;
void solve() {
	cin >> n >> m;
	int sum = 0;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	for (int i = 1; i <= m; ++i)
		cin >> b[i];
	for (int i = 1; i <= n; ++i) {
		int bitch_lasagna = 0;
		for (int j = 1; j <= m; ++j) {
			new_ending_here[j] = ans_ending_here[j];
			if (a[i] == b[j]) {
				new_ending_here[j] += bitch_lasagna;
				new_ending_here[j] += 1;
				new_ending_here[j] %= M;
			}
			bitch_lasagna += ans_ending_here[j];
			bitch_lasagna %= M;
		}
		for (int j = 1; j <= m; ++j) 
			ans_ending_here[j] = new_ending_here[j];
	}
	for (int j = 1; j <= m; ++j)
		sum += ans_ending_here[j], sum %= M;
	cout << (sum + 1) % M;
}	
 	

Measured memory_bytes: 384
from math import ceil, log10
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(2, ceil(log10(n))):
        tmp = [
            int("".join(x))
            for x in product("753", repeat=i + 1)
            if "7" in x and "5" in x and "3" in x
        ]
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 63728
cnt :: String -> (Int,Int)
cnt [] = (0,1)
cnt (n:ns) = if n == '1' then (1+ (fst (cnt ns)),snd (cnt ns))
  else (0,read [n])

main :: IO ()
main = do
  ns <- getLine
  k <- readLn :: IO Int
  if fst( cnt ns )>= k then print 1 else print $ snd (cnt ns)


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

#define IOS ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0)
#define endl "\n"
#define int long long
typedef vector<int> vi;
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define OO 0x3f3f3f3f

const double eps=(int)1e-9;
const int MOD=998244353;
const int N=998244353;


template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <typename T> T exp(T b, T p){T x = 1;while(p){if(p&1)x=(x*b);b=(b*b);p=p>>1;}return x;}
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
int count_digit(int n){
    int cnt=0;
    while(n>0){
        cnt++;
        n/=10;
    }
    return cnt;
}
int32_t main() {
    IOS;
    int n,m;
    cin>>n>>m;

    vi arr[n+2];
    vector<pair<int,int> >  per;
    for(int i=0;i<m;i++){
        int p,y;
        cin>>p>>y;
        per.emplace_back(p,y);
        arr[p].emplace_back(y);
    }
FOR(i,1,n){
        sort(arr[i].begin(),arr[i].end());
    }
    for (int j = 0; j < per.size(); ++j) {
        int cnt=count_digit(per[j].first);
        FOR(i,1,6-cnt)cout<<'0';
        cout<<per[j].first;
        int idx=upper_bound(arr[per[j].first].begin(),arr[per[j].first].end(),per[j].second)-arr[per[j].first].begin();
        cnt=count_digit(idx);
        FOR(i,1,6-cnt)cout<<'0';
        cout<<idx;
        cout<<endl;
    }

    cout<<endl;
}

Measured memory_bytes: 8560
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    if(n&1)
    {
        cout<<0<<endl;
    }
    else
    {
        ll cc=0;
        ll temp=5;
        while(n>=(2*temp))
        {
            ll r;
            r = n/(2*temp);
            cc+=r;
            temp = 5*temp;
        }
        cout<<cc<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
// agc034_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt");
    cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;

    ll ans = 0;
    REP(i, S.size()){

        if (S[i] == 'A') {
            int a = 1;
            i += 1;

            while (i < S.size()){
                if (S[i] == 'A'){
                    a += 1;
                    i += 1;
                } else if (i < S.size() - 1 &&  S[i] == 'B' && S[i+1] == 'C') {
                    ans += a;
                    i += 2;
                } else {
                    break;
                }
            }
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int dp[100000];
int vis[100000]={0};
vector<vector<int>> v(100000);
int ans=0;
void dfs(int ci){
    vis[ci]=1;
    int l=-1;
    for(auto x : v[ci]){
        if(dp[x]==-1) dfs(x);
        l=max(l,dp[x]);
    }
    dp[ci]=l+1;
    ans=max(ans,l+1);
}
int main() {
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b; cin>>a>>b; a--; b--;
        v[a].push_back(b);
    }
    for(int i=0;i<n;i++){
        dp[i]=-1;
    }
    for(int i=0;i<n;i++){
        if(vis[i]==0){
            dfs(i);
        }
    }
    cout<<ans;
}

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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut residences: [[[i8; 10]; 3]; 4] = [[[0; 10]; 3]; 4];

    let n: u8 = read();
    for _ in 0..n {
        let b: usize = read();
        let f: usize = read();
        let r: usize = read();
        let v: i8 = read();
        residences[b - 1][f - 1][r - 1] += v;
    }

    let mut building_index: u8 = 0;
    for building in residences.iter() {
        for floor in building.iter() {
            for room in floor.iter() {
                print!(" {}", room);
            }
            println!();
        }
        building_index += 1;
        if building_index != 4 {
            println!("####################")
        }
    }
}



Measured memory_bytes: 5032
using System;
class Program
{    static void Main(String[] args){
  
    string[] str = Console.ReadLine().Split(' ');
    int a = int.Parse(str[0]);
    if (a<1200){
        Console.WriteLine("ABC");
        }else if(a<2800){
            Console.WriteLine("ARC");
        }else {
            Console.WriteLine("AGC");
        }
    }
}


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

namespace AtCorder
{
    class Program
    {

        static void Main(string[] args)
        {

            //var input = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = int.Parse(Console.ReadLine());
            var d = int.Parse(Console.ReadLine());
            var e = int.Parse(Console.ReadLine());

            
 
            var k = int.Parse(Console.ReadLine());

            if(k >= e - a)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  int a,b;
  cin>>a>>b;
  if(a+b<10) cout<<a+b<<endl;
  else cout<<"error"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int max(int a,int b){
	return a>b?a:b;
}
int main(void){
	int l,a,b,c,d,j,m,maxd;
	scanf("%d %d %d %d %d",&l,&a,&b,&c,&d);
	j=a/c+(a%c?1:0);
	m=b/d+(b%d?1:0);
	maxd=max(j,m);
	printf("%d\n",l-maxd);
	return 0;
}

Measured memory_bytes: 596
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

typedef vector<int> vi;
const int maxn=100111;

int n,k;
vi operator *(const vi&a,const vi&b)
{
	vi ret(n);
	for(int i=0;i<n;i++)ret[i]=a[b[i]];
	return ret;
}
vi neg(const vi&a)
{
	vi ret(n);
	for(int i=0;i<n;i++)ret[a[i]]=i;
	return ret;
}
bool vis[maxn];
int seq[maxn];
vi qpow(const vi&a,int k)
{
	vi ret(n);
	memset(vis,0,sizeof(vis));
	for(int i=0;i<n;i++)if(!vis[i])
	{
		int tot=0,tmp=i;
		while(!vis[tmp])
		{
			seq[tot++]=tmp;vis[tmp]=1;
			tmp=a[tmp];
		}
		for(int j=0;j<tot;j++)ret[seq[j]]=seq[(j+k)%tot];
	}
	return ret;
}
vi conj(const vi&a,const vi&b){return a*b*neg(a);}


int main()
{
	get2(n,k);
	vi p,q;
	for(int i=0,x;i<n;i++)
	{
		get1(x);x--;
		p.pb(x);
	}
	for(int i=0,x;i<n;i++)
	{
		get1(x);x--;
		q.pb(x);
	}
	vi comm=q*neg(p)*neg(q)*p;comm=qpow(comm,(k-1)/6);
	p=conj(comm,p);q=conj(comm,q);
	for(int i=(k-1)/6*6+1;i<k;i++)
	{
		vi nv=q*neg(p);
		p=q;
		q=nv;
	}
	for(int i=0;i<n;i++)printf("%d ",p[i]+1);puts("");
	return 0;
}

Measured memory_bytes: 3264
#include<stdio.h>
int main(){
  int x,y;
  scanf("%d%d",&x,&y);
  if(y%2==1)
    puts("No");
  else{
    y/=2;
    if(x<=y && y<=2*x)
      puts("Yes");
    else
      puts("No");
  }
  return 0;
}


Measured memory_bytes: 1644
from collections import deque 
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
p_que = deque()
q_que = deque()
for i in range(n):
    p_que.appendleft(p[i])
    q_que.appendleft(q[i])

def culc_num(n, que):
    li = []
    count = 0
    for i in range(n):
        li.append(i+1)
    for i in range(n):
        num = que.pop()
        index= li.index(num)
        dif = index
        for i in range(1,len(li)):
            dif*=i
        count+=dif
        li.remove(num)
    return count

print(abs(culc_num(n, q_que) - culc_num(n, p_que)))





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

heights = list(map(int, input().split()))

flags = [1]*N

for i in range(M):
    A, B = map(int, input().split())
    
    if heights[A-1] > heights[B-1]:
        flags[B-1] = 0
        
    elif heights[A-1] < heights[B-1]:
        flags[A-1] = 0
        
    else:
        flags[A-1] = flags[B-1] = 0

print(flags.count(1))

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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int h, w; read(h, w);
  vector<vector<int>> v(h, vector<int>(w, 0));
  rep(i, 0, h) rep(j, 0, w) read(v[i][j]);
  
  vector<pair<int, int>> pth;
  vector<pair<pii, pii>> ans;

  rep(i, 0, h)
    rep(j, 0, w)
      pth.push_back({ i, i % 2 == 0 ? j : w - 1 - j });

  vector<pii> temp;
  for (auto p : pth) {
    int i, j; tie(i, j) = p;
    if (v[i][j] & 1) {
      if (temp.empty()) temp.push_back(p);
      else {
        temp.push_back(p);
        rep(i, 0, sz(temp) - 1)
          ans.push_back({ temp[i], temp[i + 1] });
        temp.clear();
      }
    } else {
      if (temp.size()) temp.push_back(p);
    }
  }

  write(sz(ans));
  for (auto p : ans) {
    write(p.first.first + 1, p.first.second + 1, p.second.first + 1, p.second.second + 1);
  }
}


Measured memory_bytes: 9200
from collections import deque

#スタックを使った深さ優先探索の実装
l = int(input())
rlist = []
for i in range(l):
    li = list(map(int, input().split()))
    rlist.append(deque([ll-1 for ll in li[2:]]))


color = ['white'] * l
find_time = [0] * l
stop_time = [0] * l
stack = []
time = 0

def dfs(u):
    global time

    stack.append(u)
    color[u] = 'gray'
    time += 1
    find_time[u] = time

    while len(stack) > 0:
        #print(stack)
        #print(color)
        #print(rlist)

        u = stack[-1]
        #頂点uにまだ訪問すべき頂点が残っているなら
        if len(rlist[u]) > 0:
            if color[rlist[u][0]] == 'white':
                time += 1
                find_time[rlist[u][0]] = time
                color[rlist[u][0]] = 'gray'
                stack.append(rlist[u][0])
            rlist[u].popleft()
        #頂点uにもう訪問すべき頂点が残っていないなら
        else:
            time += 1
            stop_time[u] = time
            color[u] = 'black'
            stack.pop()

for i in range(l):
    if color[i] == 'white':
        dfs(i)
for i in range(len(find_time)):
    print(str(i+1) + ' ' + str(find_time[i]) + ' ' + str(stop_time[i]))


Measured memory_bytes: 6052
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;
const int mo = 1000000007;

int n, m;
LL a[N], s[N], ss[N];

int main() {
	read(n), read(m);
	LL ans = 1, tmp;
	for (int i = 1; i <= n; i++) read(s[i]);
	sort(s + 1, s + n + 1);
	// for (int i = 1; i <= n; i++) printf("%lld\n", s[i]);
	for (int i = 1; i <= n; i++) ss[i] = (ss[i - 1] + s[i]) % mo;
	tmp = 0;
	for (int i = 1; i <= n; i++) {
		// printf("%lld %lld\n", i * s[i], ss[i]);
		(tmp += (1LL * i * s[i] % mo - ss[i]) % mo) %= mo;
	}
	ans = ans * tmp % mo;

	// printf("%lld\n", ans);

	n = m;
	for (int i = 1; i <= n; i++) read(s[i]);
	sort(s + 1, s + n + 1);
	for (int i = 1; i <= n; i++) ss[i] = (ss[i - 1] + s[i]) % mo;
	tmp = 0;
	for (int i = 1; i <= n; i++) (tmp += (i * s[i] % mo - ss[i]) % mo) %= mo;
	ans = ans * tmp % mo;

	if (ans < 0) ans += mo;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def nhr(self, n, r):  # 重複組合せ
        return self.ncr(n + r - 1, n - 1)

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

N, K = map(int, input().split())
MOD = 10**9 + 7
S = N * (N + 1) // 2

ans = 1
for d in range(N + 1):
    if N - d < K:
        break
    mx = S - (d * (d + 1) // 2)
    mi = max(0, (N - d - 1) * ((N - d - 1) + 1) // 2)
    ans += (mx - mi + 1) % MOD
    ans %= MOD
print(ans)

Measured memory_bytes: 9304
a, b, c, k = map(int, input().split())

A = 0
B = 0
C = 0
K = 0

if a >= k:
    A = k
else:
    A = a
    K = k - a
    if b >= K:
        B = K
    else:
        B = b
        K -= b
        C = K
print(A-C)

Measured memory_bytes: 9208
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n, k; cin >> n >> k;
	vector<int> a(n);

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

	k--;
	LL ans = INF2;
	for (int i = 0; i+k < n; i++) {
		int xl = a[i]; int xr = a[i + k];
		LL tmp=0;
		if (xl < 0 && xr < 0) tmp= abs(xl);
		if (xl < 0 && xr >= 0)tmp = min(abs(2 * xl) + xr, abs(xl) + 2 * xr);
		if (xl >= 0 && xr > 0)tmp = xr;
		ans = min(ans, tmp);

	}

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

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i,N){
        cin >> A[i];
    }

    if(N==2){
        cout << max(A[0], A[1]) << endl;
    }else{
        vector<int> g(N);
        vector<int> gr(N);
        g[1] = A[0];
        gr[N-2] = A[N-1];
        FOR(j,1,N-1){
            g[j+1] = __gcd(g[j], A[j]);
            gr[N-2-j] = __gcd(gr[N-1-j], A[N-1-j]);
        }
        g[0] = gr[0];
        gr[N-1] = g[N-1];

        int ans = 0;
        REP(i,N){
            ans = max(ans, __gcd(g[i], gr[i]));
        }
        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 4580
#include<bits/stdc++.h>
using namespace std ;
int main() {
 long long n  , i ,t,k,ans=1,j ;
 string s ;
 cin >> n >>s;


 for(i=1;i<n;i++){
    if (s[i]!=s[i-1])
        ans++ ;
 }
 cout << ans << endl ;



}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A
{
    public class Program

    {
        public static void Main(string[] args)
        {
           string line = RSt();
            line = line.Replace("/", ""); 
            Console.WriteLine(int.Parse(line) <= 20190430 ? "Heisei":"TBD");
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}


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

int main() {
  int s; cin >> s;
  int i = 1;
  if (s == 1 or s == 2) {cout << 4 << endl; return 0;}
  while (s != 4) {
    s = (s % 2 == 0 ? s / 2 : 3 * s + 1);
    i++;
  }
  cout << i + 3 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,x,n,t;
    cin>>n>>x>>t;
    if(n%x==0)
    {
    cout<<((n/x)*t);
    }
    else
    cout<<(((n/x)*t +t));
    return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

// ===============================================================================

int main() {
  int n;
  cin >> n;
  vector<int> v;

  int a = 1;
  while (a <= n) {
    v.push_back(a);
    a *= 6;
  }
  a = 9;
  while (a <= n) {
    v.push_back(a);
    a *= 9;
  }

  int dp[n + 1];  // i円払うのに必要な最小の硬貨の枚数
  for (int i = 0; i <= n; i++) dp[i] = INF;
  dp[0] = 0;
  for (int i = 0; i <= n; i++) {
    for (auto x : v) {
      if (i + x <= n) {  // はみ出し防止
        dp[i + x] = min(dp[i + x], dp[i] + 1);
      }
    }
  }

  cout << dp[n] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

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

  ll sum = 0;

  vec a(n+1);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j+=i) {
      a[j]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    sum += ll(i)*a[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 42308
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"--------------------------"<<endl; 
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    string s;
    cin >> s;
    if(s[0] == 'R' and s[1] == 'R' and s[2] == 'R'){
    	cout << 3 << endl;
    }
    else if((s[0] == 'R' and s[1] == 'R') or (s[1] == 'R' and s[2] == 'R')){
    	cout << 2 << endl;
    }
    else if(s[0] == 'R' or s[1] == 'R' or s[2] == 'R'){
    	cout << 1 << endl;
    }
    else{
    	cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n,k;
    while(cin >> n >> k, n||k){
        int s[105];
        bool c = true;
        rep(i,k) cin >> s[i];
        rep(i,n){
            rep(j,k){
                int inp;
                cin >> inp;
                s[j]-=inp;
                if(s[j] < 0) c = false;
            }
        }
        if(c) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1152
import java.util.Scanner;

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

        while (sc.hasNext()) {
            String[] weightBinary = new StringBuffer(Integer.toBinaryString(Integer.parseInt(sc.next()))).reverse().toString().split("");

            for (int i = 0; i < weightBinary.length; i++) {
                if ("1".equals(weightBinary[i])) {
                    if (i == weightBinary.length - 1) {
                        System.out.println((int) Math.pow(2, i));
                    } else {
                        System.out.printf("%d ", (int) Math.pow(2, i));
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 26180
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<queue>
#include<deque>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001
using namespace std;
typedef long long ll;

int n, k;
int a[100100];

int main(){
  std::cin >> n >> k;
  int one;
  rep(i,1,n+1){
    std::cin >> a[i];
    if(a[i]==1)one=i;
  }
  int left = one-1;
  int right = n-one;
  int res = 0;

  int ans = (n-1)/(k-1);
  if((n-1)%(k-1)!=0)ans++;
  std::cout << ans << '\n';
}


Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC090.C
{
    class Program
    {
        static void Main ()
        {
            decimal[] inputs = Console.ReadLine ().Split (' ')
                .Select (elem => decimal.Parse (elem))
                .ToArray ();
            decimal N = inputs[0];
            decimal M = inputs[1];
            decimal result = 0;
            if (N < 2 && M < 2) { result = 1; }
            else if (M == 1) result = N - 2;
            else if (N == 1) result = M - 2;
            else
            {
                result = (N - 2) * (M - 2);
            }
            Console.WriteLine (result);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int debt = 100000;
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        debt += debt / 20;
        if (debt % 1000 != 0) {
            debt += 1000 - (debt % 1000);
        }
    }
    std::cout << debt << std::endl;
}



Measured memory_bytes: 3112
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var a = cin.nextInt();            
            Console.WriteLine(a + Math.Pow(a,2) + Math.Pow(a, 3));
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 27940
#include <stdio.h>
#include <string.h>
int main(void)
{
	char a[1001];
	int i=0;
	int x=0;
	
	for (;;)
	{
		x=0;
		scanf("%s", a);
		
		if (!strcmp(a, "0"))
		{
			return 0;
		}
		
		for (i=0;i<1000;i++)
		{
			if (a[i]==0)
			{
				break;
			}

			x+=a[i]-'0';
		}

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

Measured memory_bytes: 536
#include<stdio.h>
#include<stdlib.h>
#define Max 2000000
#define vMax 10000

int main(){
  unsigned short *A, *B;

  int c[vMax + 1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for(i = 0 ; i <= vMax ; i++) c[i] = 0;

  for(i = 0 ; i < n ; i++){
    scanf("%hu", &A[i + 1]);
    c[A[i + 1]]++;
  }

  for(i = 1 ; i <= vMax ; i++) c[i] = c[i]+ c[i - 1];

  for(j = 1 ; j <= n ; j++){
    B[c[A[j]]] = A[j];
    c[A[j]]--;
  }

  for(i = 1 ; i <= n ; i++){
    if(i > 1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 9588
#include<stdio.h>
#define MAX 2000000

int J,S[MAX];
void maxHeap(int);

int main(){
  int i;

scanf("%d",&J);
 for(i=1;i<=J;i++){
   scanf("%d",&S[i]);
 }
 for(i=J/2;i>=1;i--){
   maxHeap(i);
 }
 for(i=1;i<=J;i++){
   printf(" %d",S[i]);
 }
 printf("\n");
 return 0;
}

void maxHeap(int i){
  int a,k,e,largest;
  k=2*i;
  e=2*i+1;
  if(k<=J && S[k] > S[i])largest = k;
  else largest = i;
  if(e <= J && S[e] > S[largest])largest = e;
  if(largest != i){
    a=S[i];
    S[i]=S[largest];
    S[largest]=a;
    maxHeap(largest);
  }
}


Measured memory_bytes: 3668
N=int(input())
A=list(map(int, input().split()))
Q=int(input())
BC=[list(map(int, input().split())) for i in range(Q)]
nums=[0]*(10**5+1)

for i in range(N):
  nums[A[i]]+=1
  
sums=0
for i in range(1, 10**5+1):
  sums+=i*nums[i]

for i in range(Q):
  sums-=nums[BC[i][0]]*BC[i][0]
  sums+=nums[BC[i][0]]*BC[i][1]
  print(sums)
  nums[BC[i][1]]+=nums[BC[i][0]]
  nums[BC[i][0]]=0
  

Measured memory_bytes: 32188
#include<stdio.h>
#include<math.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int ans = b;
  if(b < 10){
    ans += a * 10;
  }else if(b < 100){
    ans += a * 100;
  }else{
    ans += a * 1000;
  }
  if(pow(ans,0.5) == (int)pow(ans,0.5)){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; cin >> n;
    ll ans=0;
    ll now=n;
    rep(i,n){
        ans+=now*(i+1);
        now--;
    }
    rep(i,n-1){
        ll a,b; cin >> a >> b;
        if(a>b) swap(a,b);
        ans-=(1+a-1)*(1+n-b);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <deque>

using int64 = long long;

template<class T>
using vec = std::vector<T>;

class BIT {
  public:
    int n;
    vec<int> bit;
    
    BIT(int N)
    {
        n = N + 1;
        bit.assign(n, 0);
    }

    int sum(int i)
    {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
  
    void add(int i, int x)
    {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

int64 solve(const std::string &S)
{
    int N = S.size();
    std::deque<int> pos[26];
    for (int i = 0; i < N; i++) {
        pos[S[i] - 'a'].emplace_back(i); 
    }
    
    for (int i = 0; i < 26; i++) {
        if (pos[i].size() & 1) {
            return -1;
        }
    }
    
    int64 res = 0;
    vec<bool> used(N);
    BIT b(2 * N);
    for (int i = 0; i < N; i++) {
        b.add(i + 1, +1);
    }
    
    for (int i = 0; i < N; i++) {        
        int v = S[i] - 'a';       
        if (used[i]) continue;
        
        int pb = pos[v].back();
        pos[v].pop_front(); used[pb] = 1;        
        res += b.sum(2 * N - i) - b.sum(pb + 1);
        b.add(pb + 1, -1);
        b.add(2 * N - i, +1);
        pos[v].pop_back();
    }
    return res;
}

int main()
{
    std::string S;
    std::cin >> S;
    std::cout << solve(S) << std::endl;
    return 0;
}

Measured memory_bytes: 8196
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma comment(linker, "/stack:268435456")
#pragma GCC optimize("O3")
#define ll long long
#define str string
#define rtn return
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define db long double
#define MOD 1000000007
#define INF 1e18
#define EPS 1e-15
#define pll pair <ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define value_at find_by_order
#define index_of order_of_key
#define fill(a,v) memset(a,v,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define loop1(i,n) for (int i=1;i<=n;++i)
#define loop(i,begin,end) for (__typeof(end) i =(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif


template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define N 100005

ll n;
ll a[N], b[N], c[N];
ll dp[N][4];

int main() {
  FAST_IO;
  cin >> n;
  rep(i, n) {
    cin >> a[i] >> b[i] >> c[i];
  }
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  loop(i, 1, n) {
    dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
    dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
  }
  ll ans = 0;
  rep(i, 3) remax(ans, dp[n - 1][i]);
  cout << ans;
  rtn 0;
}


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

int main() {
 int N;
 cin >> N;
 int L;
 cin >> L;

 vector<string> vec(N);
 for(int i=0; i<N; i++) cin >> vec.at(i);

 sort(vec.begin(), vec.end());

 for(int i=0; i<N; i++) cout<<vec.at(i);

 cout <<endl;
}


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

using ll = long long;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (ll i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

template<typename T> using pop_max = std::priority_queue<T>;
template<typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T> void LOG(const T& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T> void LOG(const vector<vector<T>>& a) { for (const auto& x : a) LOG(x); }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; }
ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll gcd(const vector<ll>& v) { return accumulate(v.begin(), v.end(), 1LL, static_cast<ll(*)(ll, ll)>(gcd)); }
ll lcm(const vector<ll>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll(*)(ll, ll)>(lcm)); }
ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
ll inv(ll x, ll m) { return pow(x, m - 2, m); }

template<typename T> bool chmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<typename T> bool chmin(T& x, const T& y) { return x > y ? x = y, true : false; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_cpp;

const ll INF = inf<ll>;
using P = pair<ll, ll>;
const ll M = 1000000007;
signed main() {
  ll n;
  cin >> n;
  if(n==2){
    cout << 1 << endl;
    exit(0);
  }
  auto divs = [&](ll n) -> vector<ll> {
    ll i = 2;
    vector<ll> ret;
    while (i*i<=n){
      if (n%i==0){
        ret.push_back(i);
        if(i!=n/i)ret.push_back(n / i);
      }
      i += 1;
    }
    ret.push_back(n);
    return ret;
  };
  ll ans = 0;
  for(ll k : divs(n-1)){
    ll m = n;
    while (m >= k) {
      if (m % k == 0) m /= k;
      else m %= k;
    }
    if (m == 1) ans++;
  }
  for(ll k : divs(n)){
    ll m = n;
    while (m >= k) {
      if (m % k == 0) m /= k;
      else m %= k;
    }
    if (m == 1) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
h, w = map(int, input().split())
a = []
for i in range(h):
  s = input()
  if s.count('#') > 0:
    a.append(s)

b = [0 for i in range(w)]
for gl in a:
  for i in range(w):
    if gl[i] == '#':
      b[i] += 1
for gl in a:
  v = ''
  for i in range(w):
    if b[i] > 0:
      v += gl[i]
  print (v)



Measured memory_bytes: 8992
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#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 forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    cout<<(h2*60+m2-h1*60-m1-k)<<endl;
    return 0;
}



Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main (void) {
    int N, M;
    map<string, int> cost;

    string s;
    cin >> N;
    for ( int i=0; i<N; i++ ) {
        cin >> s;
        cost[s]++;
    }
    cin >> M;
    for ( int i=0; i<M; i++ ) {
        cin >> s;
        cost[s]--;
    }

    int ans = 0;
    for ( auto cost_ : cost )
        ans = max(ans, cost_.second);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256