akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main()
{
    int H, W;
    std::cin >> H >> W; // 高さ H と幅 W 

    std::string S[H]; // 文字列の配列．

    for(int h=0; h<H; h++) // SにS_hを代入．ここで配列の中に文字列が入ってることに注意．
    {
        std::cin >> S[h];
    }

    for(int h=0; h<H; h++) // hを動かす．
    {
        for(int w=0; w<W; w++) // wを動かす
        {
            if(S[h][w]=='.') // h, w が爆弾ではないときに処理をすすめる
            {
                int cnt = 0;

                //上の行
                if(h!=0) // h=0のとき飛ばす
                {
                    if(w!=0 && S[h-1][w-1]=='#') 
                    //左端ではないときに左上のカウント
                    cnt++;

                    if(S[h-1][w]=='#')
                    //真上のカウント
                    cnt++;

                    if(w!=W-1 && S[h-1][w+1]=='#')
                    //右端ではないときに右上のカウント
                    cnt++;
                }

                //同じ行
                    if(w!=0 && S[h][w-1]=='#') 
                    //左端ではないときに左上のカウント
                    cnt++;

                    if(w!=W-1 && S[h][w+1]=='#')
                    //右端ではないときに右上のカウント
                    cnt++;

                //下の行
                if(h!=H-1) // h=Hのとき飛ばす
                {
                    if(w!=0 && S[h+1][w-1]=='#') 
                   //左端ではないときに左上のカウント
                    cnt++;

                    if(S[h+1][w]=='#')
                    //真上のカウント
                    cnt++;

                    if(w!=W-1 && S[h+1][w+1]=='#')
                    //右端ではないときに右上のカウント
                    cnt++;
                }
                // ここまでで周りの爆弾を数えた

                std::cout << cnt;
            }
            // ここまで爆弾ではないときの処理

            else
            {
                std::cout << '#';
            }
            
        }

        std::cout << std::endl;
    }

    

}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;
using ll = long long;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

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

  if(x==0) cout << 1 <<endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int H, N, A[1000], B[1000], i, maxDamage = 0;
	cin >> H >> N;
	int tmpA, tmpB;
	map<int, int> mii;
	for (i = 0; i < N; i++) {
		cin >> tmpA >> tmpB;
		// 同じダメージでよりコストが低い魔法があった場合、
		// コストが高い魔法は絶対に使わないので枝刈りする
		if (mii[tmpA] == 0 || mii[tmpA] > tmpB) mii[tmpA] = tmpB;
	}
	// AとBに入れ直す
	auto itr = mii.begin();
	auto end = mii.end();
	for (i = 0; itr != end; itr++, i++) {
		A[i] = itr->first;
		B[i] = itr->second;
		if (maxDamage < itr->first) maxDamage = itr->first;
	}
	N = mii.size();

	// maxダメージは体力10000+オーバーキルダメージ10000
	int dp[20000];

	dp[0] = 0;
	for (int targetDamage = 1; targetDamage < H + maxDamage; targetDamage++) {
		dp[targetDamage] = -1;
		for (int mahouKind = 0; mahouKind < N; mahouKind++) {
			if (targetDamage < A[mahouKind]) continue;
			if (dp[targetDamage - A[mahouKind]] == -1) continue;
			int tmp = dp[targetDamage - A[mahouKind]] + B[mahouKind];
			if (dp[targetDamage] == -1 || dp[targetDamage] > tmp) dp[targetDamage] = tmp;
		}
	}

	int minCost = 100000000;
	for (int targetDamage = H; targetDamage < H + maxDamage; targetDamage++) {
		if (dp[targetDamage] == -1) continue;
		if (minCost > dp[targetDamage]) minCost = dp[targetDamage];
	}

	cout << minCost << endl;

	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3

def main():
    N, A, B = map(int, open(0).read().split())

    if (N % (A+B) >= A):
        print(A * (N // (A+B)) + A)
    else:
        print(A * (N // (A+B)) + (N % (A+B)))


main()

Measured memory_bytes: 2940
#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, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    int H, W, N;
    cin >> H >> W >> N;
    int cnt = 0;
    int black = 0;
    while (N > black) {
        black += max(H, W);
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
typedef long long LL;
const int MaxN = 3e5;
using namespace std;
priority_queue<int>que;
priority_queue<int , vector<int> , greater<int> > q;
int n ;
int a[MaxN + 5];
LL f[MaxN + 5] , e[MaxN + 5];
int main()
{
	while(~scanf("%d" , &n)){
		while(q.size()) q.pop();
		while(que.size()) que.pop();
		for(int i = 1;i <= 3 * n;i++) scanf("%d" , &a[i]);
		LL sum = 0;
		for(int i = 1;i <= n;i++){
			sum += a[i];
			q.push(a[i]);
		}
		f[n] = sum;
		for(int i = n + 1;i <= 2 * n;i++){
			int top = q.top();
			if(a[i] > top){
				sum -= top;
				q.pop();
				sum += a[i];
				q.push(a[i]);
			}
			f[i] = sum;
		}
		LL cnt = 0;
		for(int i = 3 * n;i >= 2 * n + 1;i--){
			cnt += a[i];
			que.push(a[i]);
		}
		e[2 * n + 1] = cnt;
		for(int i = 2 * n;i >= 1;i--){
			int top = que.top();
			if(top > a[i]){
				cnt -= top;
				que.pop();
				cnt += a[i];
				que.push(a[i]);
			}
			e[i] = cnt;
		}
		LL ans = -(1LL << 60);
		for(int i = n;i <= 2 * n;i++){
			ans = max(ans , f[i] - e[i + 1]);
		}
		printf("%lld\n" , ans);
	}
}

Measured memory_bytes: 5880
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)
int MOD = 1000000007;
long long MODPOW(long long inv,long long pow, long long mod){
    if(pow == 1) return inv % mod;
    else{
        if(pow % 2) return inv * MODPOW(inv, pow -1, mod) % mod;
        long long res = MODPOW(inv, pow/2, mod);
        return res * res % mod; 
    }
}

long long COMMOD(int a, int b){
    long long res=1; long long resinv = 1;
    for(int i = a; i>a-b; i--){
        res = res * i % MOD;
        resinv = resinv*(a-i+1) % MOD;
    }
    return res*MODPOW(resinv, MOD-2, MOD) % MOD;
}

int main() {
    int X, Y;
    cin>>X>>Y;
    int p = (2*X-Y)/3;
    int q = (2*Y-X)/3;
    int ans = 0;
    if(p >= 0 && q >= 0 && (2*Y-X)%3 == 0 && (2*X-Y)%3 == 0){
        ans = COMMOD(p+q, p);
    }
    cout << ans << endl;
}

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

int main()
{
    int N;
    string S;
    cin >> N >> S;

    int res = 0;
    for(int l=1; l<N; l++){
        int count = 0;
        int count_max = 0;
        for(int i=0; i<N-l; i++){
            if(S[i+l] == S[i]){
                count++;
            }else{
                count_max = max(count_max, count);
                count= 0;
            }
        }
        count_max = max(count_max, count);
        res = max(res, min(count_max, l));
    }
    cout<<res<<endl;

    return 0;
}

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

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if(a+b==c||a+c==b||b+c==a){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23636
n,m=gets.split.map(&:to_i)
b=Array.new(n)
m.times do
  s,c=gets.split.map(&:to_i)
  if [s,c]==[1,0]&&n!=1
    p -1
    exit
  end
  if !b[s-1] || b[s-1]==c
    b[s-1]=c
  else
    p -1
    exit
  end
end
b[0]=1 if !b[0]&&n!=1
b.each{|s|print s ? s : 0}


Measured memory_bytes: 14272
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

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

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func main() {
	n := readInt()
	sm := make(map[string]int)
	for i := 0; i < n; i++ {
		sm[readString()]++
	}
	var keys []string
	for k := range sm {
		keys = append(keys, k)
	}

	m := readInt()
	tm := make(map[string]int)
	for i := 0; i < m; i++ {
		tm[readString()]++
	}
	max := 0
	for _, v := range keys {
		v := sm[v] - tm[v]
		if v > max {
			max = v
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	cout<<fixed<<setprecision(10)<<sqrt(d)<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using ProCon.Util;

namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {
            AC134C();
        }

        static void AC134C()
        {
            //https://atcoder.jp/contests/abc135/tasks

            var N = int.Parse(Console.ReadLine());
            int maxNum = 0, maxNumIndex = 0, maxNumCount = 0, nextNum = 0;


            for (int i = 0; i < N; i ++ )
            {
                var a = int.Parse(Console.ReadLine());
                if(a > maxNum)
                {
                    nextNum = maxNum;
                    maxNum = a;
                    maxNumCount = 1;
                    maxNumIndex = i;
                }
                else if ( a == maxNum)
                {
                    maxNumCount++;
                    nextNum = a;
                }
                else if (maxNum > a && a >= nextNum)
                {
                    nextNum = a;
                }
            }

            if(maxNumCount > 1)
            {
                for(int i = 0; i < N; i++)
                {
                    Console.WriteLine(maxNum);
                }
            }
            else
            {
                for (int i = 0; i < N; i++)
                {
                    if (i == maxNumIndex)
                    {
                        Console.WriteLine(nextNum);
                    }
                    else
                    {
                        Console.WriteLine(maxNum);
                    }
                }
            }

            //Console.WriteLine();
            //Console.ReadKey();
        }

    }
}


Measured memory_bytes: 16584
mod=1e9+7
def addself(a):
    if(a<mod):
        return a
    else:
        return (a+mod)%mod
    
n,m=map(int,input().split())
x = []
dp = [[0 for i in range(m+1)] for j in range(n+1)]
dp[1][1] = 1
for i in range(n):
    l = list(input())
    x.append(l)
for i in range(1,n+1):
    for j in range(1,m+1):
        if i ==1 and j==1:
            continue
        if x[i-1][j-1]=='#':
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i-1][j]+dp[i][j-1]

        dp[i][j]=addself(dp[i][j])
            
print(int(dp[-1][-1]))


Measured memory_bytes: 44516
N,K = map(int,input().split())
PP = list(map(int,input().split()))


mind = -1
mmax = -1

sums = []
csum = 0

for i in range(N):
    p = PP[i]
    csum += (p+1)/2
    sums.append(csum)
    if i < K:
        if mmax < csum:
            mind = i
            mmax = csum
    else:
        ksum = csum - sums[(i-K)]
        if mmax < ksum:
            mind = i
            mmax = ksum


print(mmax)

       




Measured memory_bytes: 24812
n = int(input())
a = []
b = []
for i in range(n):
    s = int(input())
    if s%10 == 0:
        b.append(s)
    else:
        a.append(s)
a.sort()
b.sort()
if a:
    if sum(a)%10 == 0:
        print(sum(a)-a[0]+sum(b))
    else:
        print(sum(a)+sum(b))        
else:
    print(0)

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

struct Node {
  int key;
  Node *right, *left, *parent;  
};

Node  *NIL;

struct BST {
  Node *root;

  BST() {
    root = NIL;
  }

  void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z = (Node *)malloc(sizeof(Node));    
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while ( x != NIL ) {
      y = x;
      if ( z->key < x->key ) {
	x = x->left;
      } else {
	x = x->right;
      }
    }

    z->parent = y;
    if ( y == NIL ) {
      root = z;
    } else {
      if ( z->key < y->key ) {
	y->left = z;	
      } else {
	y->right = z;
      }
    }
  }

  bool find(int k) {
    Node *u = root;
    while ( u != NIL ) {
      if ( k == u->key ) {
	return true;
      } else if ( k < u->key ) {
	u = u->left;
      } else {
	u = u->right;
      }
    }

    return false;
  }
};

void inorder(Node *u) {
  if ( u == NIL ) return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);  
}

void preorder(Node *u) {
  if ( u == NIL ) return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);  
}

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

  BST bst;
  while ( m-- ) {
    string c;
    cin >> c;
    int n;
    if ( c == "insert" ) {      
      cin >> n;
      bst.insert(n);      
    } else if ( c == "find" ) {
      cin >> n;
      if ( bst.find(n) ) cout << "yes" << endl;
      else cout << "no" << endl;
    } else {
      inorder(bst.root);
      cout << endl;
      preorder(bst.root);
      cout << endl;      
    }
  }
  
  return 0;
}




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

using namespace std;

typedef long long ll;

ll MOD = 1e9+7;

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

	int N, K;
	cin >> N >> K;

	static ll dp[51][51][2501];
	rep(i, N+1) rep(j, N+1) rep(k, N*N+1) dp[i][j][k] = 0;
	dp[0][0][0] = 1;

	rep(i, N) rep(j, N) rep(k, K+1){
		if(k + 2*j > N*N) continue;

		// 今の玉を今の箱に入れる
		dp[i+1][j][k+2*j] += dp[i][j][k];
		dp[i+1][j][k+2*j] %= MOD;

		// 今の玉を保留箱に入れ、今の箱を保留
		dp[i+1][j][k+2*j] += j * dp[i][j][k];
		dp[i+1][j][k+2*j] %= MOD;

		// 今の玉を保留箱に入れ、今の箱に保留玉を入れる
		if(j-1 >= 0){
			dp[i+1][j-1][k+2*j] += j * j * dp[i][j][k];
			dp[i+1][j-1][k+2*j] %= MOD;
		}

		// 今の玉を保留、今の箱に保留玉を入れる
		dp[i+1][j][k+2*j] += j * dp[i][j][k];
		dp[i+1][j][k+2*j] %= MOD;

		// 今の玉を保留、今の箱も保留
		if(j+1 <= N){
			dp[i+1][j+1][k+2*j] += dp[i][j][k];
			dp[i+1][j+1][k+2*j] %= MOD;
		}
	}

	cout << dp[N][0][K] << endl;
}


Measured memory_bytes: 51072
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Cryptography;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);

        long min = long.MaxValue;

        for(int i=-100; i<=100; i++) {
            long sum = 0;
            foreach(var x in ary) {
                sum += (x - i) * (x - i);
            }
            min = Math.Min(min, sum);
        }

        return min;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int n;
  int mi = INF;
  int ans = 0;
  cin >> n;
  LOOP(i,n){
    int a;
    cin >> a;
    if(a>=mi)continue;
    else{
      mi = a;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

lst = inputs[0]
xx = lst[2] - lst[0]
yy = lst[3] - lst[1]

# body
if $debugFlag
end

ans = ""
if yy >= 0
  ans += "U"*yy
else
  ans += "D"*yy
end

if xx >= 0
  ans += "R"*xx
else
  ans += "L"*xx
end

if yy >= 0
  ans += "D"*yy
else
  ans += "U"*yy
end

if xx >= 0
  ans += "L"*xx
else
  ans += "R"*xx
end

#### 2

if yy >= 0
  ans += "D"
else
  ans += "U"
end

if xx >= 0
  ans += "R"*(xx + 1)
else
  ans += "L"*(xx + 1)
end

if yy >= 0
  ans += "U"*(yy + 1)
else
  ans += "D"*(yy + 1)
end

if xx >= 0
  ans += "L"
else
  ans += "R"
end

#### 2 return

if yy >= 0
  ans += "U"
else
  ans += "D"
end

if xx >= 0
  ans += "L"*(xx + 1)
else
  ans += "R"*(xx + 1)
end

if yy >= 0
  ans += "D"*(yy + 1)
else
  ans += "U"*(yy + 1)
end

if xx >= 0
  ans += "R"
else
  ans += "L"
end

puts ans


Measured memory_bytes: 1916
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

#define NIL NULL
#define N 3
#define N2 9
#define M 10000000

Node root;

typedef struct{
  int f[N2];
  int space;
  int path;
}Puzzle;

int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int sum,head=0,tail=0;
Puzzle Q[M];

void push(Puzzle a){
  Q[tail]=a;
  tail=(tail+1)%M;
}

Puzzle pop(void){
  head=(head+1)%M;
  return Q[head-1];
}


int isTarget(Puzzle p){
  int i;
  for(i=0;i<N2;i++){
    if(p.f[i]!=(i+1)) return 0;
  }
  return 1;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u; 
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

int search(Puzzle a){
  int i,m=1,k;
  sum=0;
  for(i=0;i<N2;i++){
    sum+=a.f[i]*m;
    m*=10;
  }
  if(treeSearch(root,sum)==NIL) return -1;
  else return 1;
}



void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;

  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
 
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else y->right=z;
}


int bfs(Puzzle s){
  Puzzle u,v;
  int r,x;
  s.path=0;
  push(s);

  while(head!=tail){
    u=pop();
    //     printf("%d %d %d\n%d %d %d\n%d %d %d\n",u.f[0],u.f[1],u.f[2],u.f[3],u.f[4],u.f[5],u.f[6],u.f[7],u.f[8]);
    if(isTarget(u)) return u.path;
    int sx=u.space/N, sy=u.space%N;
    for(r=0;r<4;r++){
      int tx=sx+dx[r], ty=sy+dy[r];
      if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
      v=u;
      
      x=v.f[u.space];
      v.f[u.space]=v.f[tx*N + ty];
      v.f[tx*N + ty]=x;
     
      v.space=tx*N + ty;
      if(search(v)==-1){
	v.path++;
	push(v);
	insert(sum);
      }
    }
  }
  return 0;
}

int main(){
  Puzzle in;
  int i;
  for(i=0;i<N2;i++){
    scanf("%d",&in.f[i]);
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }

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



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

const int N = 1e5+7;
long long a[N], b[N];

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

    int n;
    cin>>n;

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

    long long add = 0;
    for (int i=n; i>0; i--) {
        a[i] += add;
        if (a[i]%b[i] != 0) add += b[i] - a[i]%b[i];
    }
    cout<<add<<endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int source = Integer.parseInt(sc.next());
        int target = Integer.parseInt(sc.next());
        int[] palace = new int[n];
        int ans = 0;
        double min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i ++) {
            palace[i] = Integer.parseInt(sc.next());
            double tmp = (source-(palace[i] * 0.006));
            if (min > Math.abs(tmp - target)) {
                 min = Math.abs(tmp - target);
                 ans = i;
            }
        }
        System.out.println(ans + 1);
    }
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = N; i > 0 ; i--) {
        string s = to_string(i);
        if (s.length() % 2 == 1) {
            ans ++;
        }
    }
    cout << ans << endl;

}

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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	ans := make([]byte, 0, 100)
	for scanner.Scan() {
		p := true
		for _, t := range scanner.Bytes() {
			if p && t != ' ' {
				ans = append(ans, strings.ToUpper(string(t))...)
			}
			p = t == ' '
		}
		break
	}

	fmt.Println(string(ans))
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll n,k;
    cin >> n >> k;

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

    vector<ll> sum(n);
    sum[0] = a[0];
    for(int i = 1; i < n; i++){
        sum[i] = sum[i-1] + a[i];
    }

    vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(n+1,0)));

    for(int i = 0; i < n; i++){
        for(int j = 0; i + j < k && j < n && i+j < n; j++){
            if(a[i] < 0){
                ll t = a[i];
                for(int x = 0; x < n+1; x++){
                    if(dp[i][j][x] <= t){
                        dp[i+1][j][x] = dp[i][j][x];
                    }else{
                        dp[i+1][j][x] = t;
                        t = dp[i][j][x];
                    }
                }
            }else{
                for(int x = 0; x < n+1; x++){
                    dp[i+1][j][x] = dp[i][j][x];
                }
            }
            if(a[n-j-1] < 0){
                ll t = a[n-j-1];
                for(int x = 0; x < n+1; x++){
                    if(dp[i][j][x] <= t){
                        dp[i][j+1][x] = dp[i][j][x];
                    }else{
                        dp[i][j+1][x] = t;
                        t = dp[i][j][x];
                    }
                }
            }else{
                for(int x = 0; x < n+1; x++){
                    dp[i][j+1][x] = dp[i][j][x];
                }
            }
        }
    }

    ll ans = 0;

    for(int i = 0; i < n+1; i++){
        for(int j = 0; i+j <= k && i + j < n+1; j++){
            ll front;
            if(i == 0){
                front = 0;
            }else{
                front = sum[i-1];
            }
            ll back = sum.back();
            if(j != n){
                back -= sum[n - j - 1];
            }
            ll tmp = front + back;
            for(int x = 0; x + i + j  < k && x < n+1; x++){
                tmp -= dp[i][j][x];
            }
            ans = max(ans,tmp);
        }
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
import std.stdio;
import std.algorithm;
import std.conv;
import std.array;
import std.string;
import std.math;
import std.functional;
import std.range;
import std.typecons;
import std.format;

void main(string[] args) {
  readln;
  readln.solve.writeln;
}

auto solve(string line1) {
  auto hash = line1.chomp.split.map!(to!long).array.counter;
  long res;
  foreach(k, v; hash) {
    if (k < v) {
      res += v - k;
    } else if (v < k) {
      res += v;
    }
  }
  return res;
} unittest {
  assert(solve("3 3 3 3") == 1, "1");
  assert(solve("2 4 1 4 2") == 2, "2");
  assert(solve("1 2 2 3 3 3") == 0, "3");
  assert(solve("1000000000") == 1, "4");
  assert(solve("2 7 1 8 2 8 1 8") == 5, "4");
}

pure auto counter(N = int, E)(E[] arr) {
  N[E] hash;
  foreach(e; arr) {
    hash[e]++;
  }
  return hash;
}

Measured memory_bytes: 9636
#include<bits/stdc++.h>
#define ll long long
#define fast_i_o ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main()
{
    ll n,m,x;
    cin>>n>>m>>x;
    ll arr[n],arr1[n][m];
    for(int i=0;i<n;i++)
    {cin>>arr[i];
        for(int j=0;j<m;j++)
            cin>>arr1[i][j];
    }
    ll ans=INT_MAX;
    for(int i=1;i<pow(2,n);i++)
    {
        ll sum=0,val=i,count1=0,a[m]={0},flag=1;
        while(val>0)
        {
            if(val%2==1)
            {
                sum+=arr[count1];
                for(int j=0;j<m;j++)
                {
                    a[j]+=arr1[count1][j];
                }
            }
            val=val/2;
            count1++;
        }
       for(int j=0;j<m;j++)
       {
           if(a[j]<x)
            flag=0;
       }
       if(flag==1)
       {
           ans=min(ans,sum);
       }
    }
    if(ans==INT_MAX)
    cout<<-1<<"\n";
    else
    cout<<ans<<"\n";
}


Measured memory_bytes: 4100
#include <iostream>
using namespace std;
int main(void){
    int n,d[100],sum=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < n; j++) {
            if(i == j) break;
            sum += d[i]*d[j];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
/*
author : rahil_1407
motto : Time Management,Consistency,Patience!!
*/

#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define f first
#define s second
#define pii pair<int,int>
#define vi vector<int>
#define mp make_pair
#define pb push_back
#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 pi 3.1415926536
#define MAX 1000005
#define ll int long long

const ll N=10e8+7;
using namespace std;

int main()
{
    SPEED;
	string s1,s2;
	cin>>s1>>s2;

	int n=s1.length();
	string k=s2.substr(0,n);

	if(k==s1)
	 cout<<"Yes"<<endl;
	else
	 cout<<"No"<<endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	string s;
	cin >> s;
	string a,b,c,d;
	int n = s.size();
	a = s.substr(0,(n-1)/2);
	b = a;
	c = s.substr((n+3)/2-1);
	d = a;
	reverse(a.begin(),a.end());
	if (a != b) {
		cout << "No" << endl;
		return 0;
	}
	if (a != c) {
		cout << "No" << endl;
		return 0;
	}
	
	reverse(c.begin(),c.end());
	if (b != c) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

	return 0;
}



Measured memory_bytes: 256
import math
N, M = [int(x) for x in input().split()]

upper_bound = int(math.sqrt(M))

qmin = M
for q in range(1, upper_bound + 1):
    if M % q != 0:  continue
    
    q2 = M // q
    if q >= N:
        qmin = q
        break
    elif q2 < N:
        break
    else: # q2 >= N
        qmin = q2

print(M // qmin)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll n,p,q;
  cin>>n;
  vector<ll> a(n),b(n);
  p=0;
  for(ll i=0;i<n;i++){
    scanf("%lld",&a[i]);
    p=p^a[i];
  }for(ll i=0;i<n;i++){
    q=p;
    q=q^a[i];
    cout<<q<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 6328
package main

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

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
	}
	bs := make([]int, n+1)
	for i := 1; i <= n; i++ {
		bs[i] = (bs[i-1] + as[i-1]) % k
	}
	for i := range bs {
		bs[i] = bs[i] - i%k
		if bs[i] < 0 {
			bs[i] += k
		}
	}
	var ans int
	m := make(map[int][]int)
	for i, v := range bs {
		if _, ok := m[v]; ok {
			for len(m[v]) > 0 && i-m[v][0] >= k {
				m[v] = m[v][1:]
			}
			ans += len(m[v])
		}
		m[v] = append(m[v], i)
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 24600
#ABC129

n = int(input())
w = list(map(int,input().split()))
m = sum(w)
for i in range(n-1):
    a = w[:i+1]
    b = w[i+1:]
    #print(a,b)
    if abs(sum(a) - sum(b)) < m:
        m = abs(sum(a) - sum(b))
        
print(m)

Measured memory_bytes: 3060
#include <atcoder/all>

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()
#define LL long long

int t;

int main(){
    cin>>t;
    REP(i,t){
        LL n,m,a,b;
        cin>>n>>m>>a>>b;
        cout<<atcoder::floor_sum(n,m,a,b)<<endl;
    }
}

Measured memory_bytes: 3668
n,k = map(int, input().split())
p = list(map(int, input().split()))
p = [(i+1)/2 for i in p]
cs = [0]
for i in p:
    cs.append(cs[-1]+i)
ma = 0
for i in range(n-k+1):
    if ma < cs[i+k]-cs[i]:
        ma = cs[i+k]-cs[i]

print(ma)

Measured memory_bytes: 78984
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int bits = 0;
  vector<int> A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
    bits ^= A[i];
  }
  for(int i=0;i<n;i++){
    cout<<(A[i]^bits)<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 3984
#include<bits/stdc++.h>
#define ll long long 
#define OJ \
        freopen("input.txt","r",stdin); \
        freopen("output.txt","w",stdout);
using namespace std;
int mod=1000000007;
int main()
{
//OJ;
 
int n;
cin>>n;
if(n==1)
{
        cout<<0;
}
else{
        cout<<1;
}
 }
     


Measured memory_bytes: 3616
#include<stdio.h>

int main(void)
{
  int H, W, N, temp=0, count=0;
  scanf("%d%d%d", &H, &W, &N);
  if(H < W){
    while(1){
      temp+= W;
      count++;
      if(temp >= N) break;
    }
  }else{
    while(1){
      temp+= H;
      count++;
      if(temp >= N) break;
    }
  }
  
  printf("%d\n", count);
  
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

ll s, n;
vector<ll> d;

ll dfs(ll num, ll sum, ll nowsum) {
  if (num == n) return sum + nowsum;
  return dfs(num+1, sum, nowsum * 10 + d[num]) + dfs(num+1, sum + nowsum, d[num]);
}

int main() {
  scanf("%lld", &s);
  while (s) d.push_back(s%10), s /= 10;
  reverse(d.begin(), d.end());
  n = d.size();
  printf("%lld\n", dfs(1, 0, d[0]));
}


Measured memory_bytes: 256
from collections import deque
n = int(input())
l = ["a","b","c","d","e","f","g","h","i","j","k"]
ansl = []
d = deque()
ans = "a"
d.append([ans,0])
while len(d):
    now,m = d.pop()
    #print(now)
    if len(now) == n:
        ansl.append(now)
    else:
        for i in range(m+2):
            if i == m+1:
                d.append([now+l[i],m+1])
            else:
                d.append([now+l[i],m])
ansl.sort()
for i in ansl:
    print(i)

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

int main(){
    int N,M;
    cin>>N>>M;
    ll int ans=0;
    //vector<pair<ll int , ll int>> AB[N];
    vector<pair<ll int, ll int> > AB(N);

    rep(i,N)cin>>AB[i].first>>AB[i].second;
    sort(AB.begin(),AB.end());
    rep(i,N){
        if(AB[i].second>M){
            ans += M*AB[i].first;
            break;
        }
        else{
            ans += AB[i].first*AB[i].second;
            M-=AB[i].second;
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  int N,M,l,r,maxl=0,minr=110000;
  cin>>N>>M;
  for(int i=0;i<M;i++){
    cin>>l>>r;
    maxl=max(maxl,l);
    minr=min(minr,r);
  }
  if(minr>=maxl) cout<<minr-maxl+1<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 888
from bisect import bisect
from collections import defaultdict


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def debug_print(self):
        for i in range(1, self.size + 1):
            j = (i & -i).bit_length()
            print('  ' * j, self.tree[i])

    def lower_bound(self, x):
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_


n, m = map(int, input().split())
xxx = list(map(int, input().split()))
yyy = list(map(int, input().split()))
ab = defaultdict(set)
coordinates = set()

for x in xxx:
    if x < yyy[0] or yyy[-1] < x:
        continue
    i = bisect(yyy, x)
    a = x - yyy[i - 1]
    b = yyy[i] - x
    ab[a].add(b)
    coordinates.add(b)

# Bitのindexは1から始まるように作っているが、"0"を取れるようにするため、全体を1ずらす
cor_dict = {b: i for i, b in enumerate(sorted(coordinates), start=2)}
cdg = cor_dict.get
bit = Bit(len(coordinates) + 1)
bit.add(1, 1)

for a in sorted(ab):
    bbb = sorted(map(cdg, ab[a]), reverse=True)
    for b in bbb:
        bit.add(b, bit.sum(b - 1))

print(bit.sum(bit.size) % (10 ** 9 + 7))


Measured memory_bytes: 89092
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            (long X, long Y) = Slice2<long>();
            if (Abs(X - Y) <= 1)
                WriteLine("Brown");
            else
                WriteLine("Alice");
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27524
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int dp[601][601];

Int rp[601][601];
Int lp[601][601];
Int np[601][601];
Int ff[601];
Int p[601];
Int n, k, a, b, K;
int main(){
  ff[0] = ff[1] = 1;
  for(int i = 2;i <= 600;i++)ff[i] = (ff[i-2] * (i-1)) % MOD;
  cin >> n >> K;
  for(int i = 0;i < K;i++){
    cin >> a >> b;
    p[a] = b;
    p[b] = a;
  }

  for(int i = 1;i <= 2*n;i++){
    for(int j = i;j <= 2*n;j++){
      if(i == j){
	if(p[i] == 0){
	  rp[i][j] = -INF;
	  lp[i][j] = INF;
	  np[i][j] = 1;	 
	}
	else{
	  np[i][j] = 0;
	  rp[i][j] = lp[i][j] = p[i];
	}
      }
      else{
	if(p[j] == 0){
	  rp[i][j] = rp[i][j-1];
	  lp[i][j] = lp[i][j-1];
	  np[i][j] = np[i][j-1]+1;
	}
	else{
	  rp[i][j] = max(rp[i][j-1], p[j]);
	  lp[i][j] = min(lp[i][j-1], p[j]);
	  np[i][j] = np[i][j-1];
	}
      }
    }
  }
  Int res=0;
  for(int i = 1;i <= 2*n;i++){
    for(int j = i;j <= 2*n;j++){
      //     cout << i << " " << j << " "<< rp[i][j] << " "<<lp[i][j] << " " << np[i][j] << endl;
      if(rp[i][j] > j || lp[i][j] < i || np[i][j] %2 == 1){
	dp[i][j] = 0;
	continue;
      }
      dp[i][j] = ff[np[i][j]];
      for(int k = i;k < j;k++){
	dp[i][j] -= dp[i][k] * ff[np[k+1][j]] %MOD;
	dp[i][j] %= MOD;
      }
      //      cout << i << " " << j << " " <<dp[i][j] << endl;
      //cout << dp[i][j] << endl;
      res += dp[i][j] * ff[(n-K)*2-np[i][j]]%MOD;
      res %= MOD;
    }
  }
  if(res < 0)res+=MOD;
  cout << res << endl;
  
  return 0;
}

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

int main() {
	int A[6];
	repeat(i, 3) {
		cin >> A[i];
		A[i + 3] = A[i];
	}

	int minimum = 0;

	repeat(i, 3) {
		repeat(ii, 2) {
			int kosuto = abs(A[i] - A[i + 1 + ii]) + abs(A[i + 1] - A[i + 2]);
			if (kosuto < minimum || minimum == 0) minimum = kosuto;
		}
	}

	cout << minimum << endl;

	return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
import heapq
 
N = int(input())
pos = [[int(p) for p in input().split()] for _ in range(N)]
 
pos.sort()
for i in range(N):
    pos[i].append(i)
    
Y = sorted(pos, key=itemgetter(1))
Y_idx = [0]*N
for i in range(N):
    Y_idx[Y[i][2]] = i
    
ans = 0
used = [0]*N
used[0] = 1
h = []
c = 1
idx = Y_idx[0]
heapq.heappush(h, (pos[c][0]-pos[c-1][0], 1))
if idx > 0:
    heapq.heappush(h, (Y[idx][1]-Y[idx-1][1], Y[idx-1][2]))
if idx < N-1:
    heapq.heappush(h, (Y[idx+1][1]-Y[idx][1], Y[idx+1][2]))
    
cnt = 0
while cnt < N-1:
    t = heapq.heappop(h)
    if used[t[1]] == 1:
        continue
    c = t[1]
    used[c] = 1
    cnt += 1
    ans += t[0]
    if c > 0 and used[c-1] == 0:
        heapq.heappush(h, (pos[c][0]-pos[c-1][0], c-1))
    if c < N-1 and used[c+1] == 0:
        heapq.heappush(h, (pos[c+1][0]-pos[c][0], c+1))
    idx = Y_idx[c]
    if idx > 0 and used[Y[idx-1][2]] == 0:
        heapq.heappush(h, (Y[idx][1]-Y[idx-1][1], Y[idx-1][2]))
    if idx < N-1 and used[Y[idx+1][2]] == 0:
        heapq.heappush(h, (Y[idx+1][1]-Y[idx][1], Y[idx+1][2]))
            
print(ans)

Measured memory_bytes: 43972
n=int(input())
if n==2:
    count=1
else:
    count=2
for i in range(2,int(n**0.5)+1):
    if n%i==0:
        k=n//i
        while k>0:
            if k%i==0:
                k=k//i
            else:
                if k%i==1:
                    count+=1
                break
    elif (n-1)%i==0:
        count+=1
        if i!=(n-1)//i:
            count+=1
print(count)


Measured memory_bytes: 3060
#include <stdio.h>

int main(int argc, char *argv[]){
    int a, b, n, ct;
    scanf("%d %d", &a, &b);
    
    if(a > b){
        n = b;
        ct = a; 
    }else{
        n = a;
        ct = b;
    }

    for(int i = 0; i < ct; i++)
    printf("%c", n+'0');

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 58;
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    string S;
    cin >> S;
    if(S == "ABC")
    cout << "ARC" << endl;
    else
    cout << "ABC" << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <map>
#include <complex>
using namespace std;
typedef complex<double> P;

int col[1000] , row[1000];
bool val[1000][1000];

typedef unsigned int uint;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}

int main(){
	int H,W;
	cin >> H >> W;
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){	
			int t = in();
			col[i] += t;
			row[j] += t;
			val[i][j] = t;
		}	
	}
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			printf("%d%c",(col[i]+row[j]+val[i][j]+1)%2,(char)(j == W-1 ? 10 : 32 ));
		}
	}
}

Measured memory_bytes: 1856
# include <bits/stdc++.h>
/// my holy template
# define F first    
# define S second
# define mp make_pair
# define pii pair<int,int>         
/// eveything goes according to plan
# define long long long  
# define pb push_back
# define sz(a) (int)(a.size())
/// countdown BEGAN. 10 , 9 , 8 ...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right     

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long MXLL = 9223372036854775807;
const int Sz = 1110111;

using namespace std;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
int main() 
{
  Read_rap ();        
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> a(n + 1);
  for (int i = 1;i <= n;i ++) cin >> a[i];
                             
  int p = 1;               
  for (int i = 1;i <= h;i ++) {
    if (i & 1) {
      for (int i = 1;i <= w;i ++) {
        
        cout << p << ' ';
        a[p] --;
        if (!a[p])  p ++;
      } 
    }
    else
    {
      vector<int> v;
      for (int i = w;i >= 1; i--) {
        v.pb (p);
        a[p] --;
        if (!a[p])  p ++;
      }    
      reverse (v.begin(), v.end());
      for (int x : v) cout << x << ' ';
    }
    cout << endl;
  }       

  return 0;
} 










// Coded by Z...

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

long long int koyaku(long long int num1, long long int num2) {
	long long int tmp;
#ifdef DEBUG
	printf("%lld %lld\n", num1, num2);
#endif // DEBUG

	if (num1 == num2) {
		return num1;
	}

	if (num2 > num1) {
		tmp = num1;
		num1 = num2;
		num2 = tmp;
	}
	if (num1%num2 != 0) {
		num1 = (num1%num2);
	}
	else {
		num1 = num2;
	}
	num1=koyaku(num1, num2);
	return num1;
}

int main(void) {
#ifdef DEBUG
	printf("");
#endif
	long long int ans;
	long long int num1, num2;
	int N;

	scanf("%d", &N);
	scanf("%lld", &ans);

	int i;
	for (i = 0; i < N - 1; i++) {
		num1 = ans;
		scanf("%lld", &num2);

		ans = num1 / koyaku(num1, num2) * num2;
	}
	
	printf("%lld\n", ans);
}


Measured memory_bytes: 128
import math
a, b, h, m = map(int, input().split())
a_d = (60*h + m)/2
b_d = 6*m
degree = abs(a_d - b_d)
cos = math.cos(math.radians(degree))
c_2 = a**2 + b**2 -2*a*b*cos
c = (math.sqrt(c_2))
print(c)


Measured memory_bytes: 9480
#include<stdio.h>
int isprime(int n){
	for(int i = 2; i * i <= n; i++){
		if(n % i == 0) return 0;
	}
	return 1;
}
int main(){
	int n, i;
	for(;;){
		scanf("%d", &n);
		if(n == 0) break;
		for(i = n - 2; i >= 2; i--){
			if(isprime(i) == 1 && isprime(i + 2) == 1){
				printf("%d %d\n", i, i + 2);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1804
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


def topological_sort(graph):
    """
    :param list of (list of int) graph:
    :return:
    """
    # 入次数
    ins = [0] * len(graph)
    for vs in graph:
        for v in vs:
            ins[v] += 1

    # 入次数がゼロのやつ
    zeros = []
    for v, cnt in enumerate(ins):
        if cnt == 0:
            zeros.append(v)

    # 入次数がゼロのやつから順に追加してく
    ret = []
    while zeros:
        v = zeros.pop()
        ret.append(v)
        for u in graph[v]:
            ins[u] -= 1
            if ins[u] == 0:
                zeros.append(u)
    return ret


V, E = list(map(int, sys.stdin.readline().split()))
ST = [list(map(int, sys.stdin.readline().split())) for _ in range(E)]

graph = [[] for _ in range(V)]
for s, t in ST:
    graph[s].append(t)

ans = topological_sort(graph)
print(*ans, sep='\n')



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

int main() 
{
    int n,m;
    cin >> n >> m;
    vector<int> vec(n);
 
    for (int i = 0; i < n; i++) {
      cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    double sum = accumulate(vec.begin(), vec.end(), 0);


  if (vec.at(n-m) >= sum/(4*m))
  {
      cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String n=sc.next();
    boolean ans=false;
    for (int i=0;i<n.length();i++) {
      if (n.charAt(i)=='7') {
        ans=true;
      }
    }

    // System.out.println(ans);

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


Measured memory_bytes: 26928
from collections import defaultdict

n = int(input())

num = 2
d = defaultdict(int)
while num * num <= n:
    while n % num == 0:
        n //= num
        d[num] += 1

    num += 1

if n != 1:
    d[n] += 1

ans = 0
for v in d.values():
    mn = 1
    while v >= mn:
        v -= mn
        ans += 1
        mn += 1

print(ans)


Measured memory_bytes: 9464
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;

using ll = long long;

int main(void)
{
    int n, k;

    cin >> n >> k;

    ll count = 0;
    
    while (n >= k) {
        n = n / k;
        count++;
    }

    count++;

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256