akhauriyash/Code-Regression huggingface dataset:
namespace VainZero.Procon.FSharp

open System
open System.Collections.Generic
open System.Linq

[<AutoOpen>]
module Operators =
  let read f = Console.ReadLine().Split([|' '|]) |> Array.map f

module Program =
  let inf = Int64.MaxValue / 3L

  // Bellman-Ford アルゴリズムの改良版
  // 点 source から点 sink への最短経路を探索し、経路の重みの最小値を求める。
  // 負閉路を経由して sink に到達できる場合、最小値はないので、 None を返す。
  let bellmanFord source sink (g: array<array<_>>) =
    let n = g.Length

    // dist.[u] = w
    // ⇔ 点 source から u への経路の重みの最小値が w である。
    let dist =
      let dist = [|for _ in 0..(n - 1) -> inf|]
      dist.[source] <- 0L
      for _ in 0..(n - 2) do
        for u in 0..(n - 1) do
          for (v, w) in g.[u] do
            if dist.[u] < inf && dist.[v] > dist.[u] + w then
              dist.[v] <- dist.[u] + w
      dist

    // unbounded.[u] = true
    // ⇔ 負閉路を経由して点 u に到達できる。
    let unbounded =
      let unbounded = [|for _ in 0..(n - 1) -> false|]
      for _ in 0..(n - 1) do
        for u in 0..(n - 1) do
          for (v, w) in g.[u] do
            // 負閉路を経由して u に到達できるなら、v にも到達できる。
            // v の最小値が dist.[v] より小さくなるなら、無限に小さくなるので、v は負閉路に含まれている。
            if unbounded.[u] || (dist.[u] < inf && dist.[v] > dist.[u] + w) then
              unbounded.[v] <- true
      unbounded

    if unbounded.[sink] then None else Some dist.[sink]

  let adjacencyList n (edges: array<_>) =
    [|
      let edgesFromSource = edges.ToLookup(fun (u, _, _) -> u)
      for u in 0..(n - 1) ->
        [|
          for (_, v, w) in edgesFromSource.[u] -> (v, w)
        |]
    |]

  [<EntryPoint>]
  let main _ =
    let [|n; m|] = read int
    let edges =
      [|
        for _ in 0..(m - 1) do
          let [|a; b; c|] = read int64
          yield (int a - 1, int b - 1, c)
      |]

    let calc () =
      // スコアを -1 倍することで、最大化問題を最小化問題 (最短経路問題) に変換する。
      let edges = [|for (u, v, w) in edges -> (u, v, -w)|]
      adjacencyList n edges
      |> bellmanFord 0 (n - 1)
      |> Option.map (~-)

    match calc () with
    | Some score ->
      printfn "%d" score
    | None ->
      printfn "inf"

    0


Measured memory_bytes: 14812
#include<stdio.h>

int main(void)
{
	int H, W, i, j;

	for (;;)
	{
		scanf("%d %d", &H, &W);
		if ((H==0)&&(W==0)) break;
		for (i = 1; i <= H; i++)
		{
			for (j = 1; j <= W; j++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}


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

using namespace std;
using ll = long long int;

constexpr int MaxN = 100000 + 10;
vector<int> G[MaxN];
vector<pair<int, int>> E;
map<pair<int, int>, int> C;
int maxCount;

void Paint(int from, int color)
{
    for (auto to : G[from])
    {
        if (C.find(make_pair(from, to)) == C.end())
        {
            C[make_pair(from, to)] = C[make_pair(to, from)] = color;
            color = (color + 1) % maxCount;
            Paint(to, color);
        }
    }
}

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

    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
        E.emplace_back(a, b);
    }

    maxCount = 0;
    for (int i = 0; i < n; i++)
    {
        maxCount = max(maxCount, (int) G[i].size());
    }

    Paint(0, 0);

    cout << maxCount << endl;
    for (auto &pair : E)
    {
        cout << C[pair] + 1 << endl;
    }
}

Measured memory_bytes: 19576
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n = int(input())
    data = sorted(int(input()) for _ in range(n))
    x, y = data[:-1], data[-1]
    print(sum(x)+y//2)


main()


Measured memory_bytes: 9028
A, B, C = map(int, input().split())
ABC = sorted([A, B, C])

ans = 0
ans += (ABC[2]-ABC[0]) // 2
ABC[0] += ((ABC[2]-ABC[0]) // 2) * 2
ans += (ABC[2]-ABC[1]) // 2
ABC[1] += ((ABC[2]-ABC[1]) // 2) * 2

if ABC[0] == ABC[1] == ABC[2]:
    print(ans)
else:
    if ABC[0] == ABC[1]:
        print(ans + 1)
    else:
        print(ans+2)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int h,w,n;
    cin >> h >> w >> n;
    int x = max(h,w);
    if(n % x == 0){
        cout << n / x << endl;
    }else{
        cout << n / x + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int Read() {
	int x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) {if(ch == '-')  f = -1; ch = getchar();}
	while(isdigit(ch)) {x = (x << 3) + (x << 1) + ch - '0'; ch = getchar();}
	return x * f;
}
char s[10005];
signed main() {
	scanf("%s", s + 1);
	int len = strlen(s + 1);
	if(s[len] == 's')  s[++len] = 'e', s[++len] = 's';
	else  s[++len] = 's';
	s[len + 1] = '\000';
	puts(s + 1);
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) long long(a.size())
#define re return
#define all(a) a.begin(),a.end()
using namespace std;
vector<long long>ans[17];
signed main()
{
	long long x;
	cin>>x;
	for (long long i=1;i<=9;i++){
		ans[0].pb(i);
	}
	for (int i=0;i<10;i++){
		for (auto j : ans[i]){
			for (long long k=max( (long long)(0) , (long long)(j%10-1) );k<=min( (long long)(9) , (long long)(j%10+1) );k++){
				ans[i+1].pb(10*j+k);
			}
		}
	}
	for (long long i=0;i<=10;i++){
		if (x>ans[i].size())  x-=ans[i].size();
		else  {cout<<ans[i][x-1];break;}
	}
	re 0;//D题
}

Measured memory_bytes: 7792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.nextLine());
        String s = sc.nextLine();

        int center = n / 2;
        String head = s.substring(0, center);
        String result = s.equals((head + head)) ? "Yes":"No";
        
        System.out.println(result);
        sc.close();
	}
}

Measured memory_bytes: 21844
#include<stdio.h>
int main(void)
{
	int n;
	scanf("%d", &n);

	char a[n];

	scanf("%s",a);

	if(a[0]==a[1] && a[1]==a[2] && a[2] && a[0]){
		puts("No");
	}else{
		puts("Yes");
	}
	return 0;
}

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

namespace AtCoder {
    public class Program {
        public static void Main() {
            string[] Keys = Console.ReadLine().Split(' ');
            int N = int.Parse(Keys[0]);
            int M = int.Parse(Keys[1]);
            City[] cities = new City[M];
            for (int i = 0; i < M; i++) {
                Keys = Console.ReadLine().Split(' ');
                cities[i] = new City(int.Parse(Keys[0]), int.Parse(Keys[1]), i);
            }
            cities = cities.OrderBy(c => c.Year).ToArray();
            int[] Count = new int[N];
            for (int i = 0; i < M; i++) {
                cities[i].Generate(Count[cities[i].Prefacture - 1] + 1);
                Count[cities[i].Prefacture - 1]++;
            }
            cities = cities.OrderBy(c => c.No).ToArray();
            for (int i = 0; i < M; i++) {
                Console.WriteLine(cities[i].Code);
            }
        }
    }

    public class City {
        public int Prefacture;
        public int Year;
        public int No;
        public string Code;
        public City(int P,int Y,int N) {
            Prefacture = P;
            Year = Y;
            No = N;
        }
        public void Generate(int i) {
            Code = Prefacture.ToString("000000") + i.ToString("000000");
        }
    }
}


Measured memory_bytes: 37208
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,m,q;
int a[55],b[55],c[55],d[55];
int ans=0;
void dfs(vector<int> v){
    if(v.size()==n){
        // rep(i,n){
        //     cout << v[i] << " ";
        // }
        // cout << " " << endl;
        int res=0;
        rep(i,q){
            if(v[b[i]-1]-v[a[i]-1]==c[i]){
                res+=d[i];
            }
        }
        ans=max(ans,res);
        return;
    }
    Rep(i,v.back(),m+1){
        vector<int> v_=v;v_.push_back(i);
        dfs(v_);
    }
}

void solve(){
    cin >> n >> m >> q;
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    //int ans=0;
    dfs(vector<int>(1,1));
    cout << ans << endl;
}

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

Measured memory_bytes: 3628
N = gets.to_i
A = gets.split.map &:to_i

A.sort!
(N/2).times do |i|
  j = 2 * i
  k = 2 * i + 1
  if A[k] < 0 || (A[j] < 0 && -A[j] > A[k])
    A[j] *= -1
    A[k] *= -1
  end
end

puts A.inject(:+)


Measured memory_bytes: 9396
// Recall: Iterating all subsets --> Iterate sub-subsets --> Total count = 3^N
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

#define FOR(i,s,e) for(int i=(s);i<(int)(e);i++)
#define FOE(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define REP(i,n)   FOR(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define CLR(s) memset(s,0,sizeof(s))
#define PB push_back

const LL MOD = 998244353LL;
const int MAX_N = 3333;
int N, S;

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

    cin >> N >> S;
    vector<int> A(N + 1);
    FOE(i, 1, N) cin >> A[i];

    std::vector<LL> Old(S + 1);
    FOE(i, 0, S) Old[i] = LL(i == 0);

    FOE(i, 1, N) {
        //cout << endl << "A) "; FOE(i, 0, S) cout << Old[i] << " "; cout << endl;

        std::vector<LL> Cur = Old;
        FOE(s, A[i], S) {
            Cur[s] += Old[s - A[i]];
            Cur[s] %= MOD;
        }
        //cout << "B) "; FOE(i, 0, S) cout << Old[i] << " "; cout << endl;
        //cout << "B) "; FOE(i, 0, S) cout << Cur[i] << " "; cout << endl;
        FOE(s, 0, S) {
            Cur[s] += Old[s];
            Cur[s] %= MOD;
        }
        //cout << "C) "; FOE(i, 0, S) cout << Cur[i] << " "; cout << endl;
        Old = std::move(Cur);
    }

    cout << Old[S] << endl;

    return 0;
}


Measured memory_bytes: 3632
def minimum_hug_to_palindrome(string)
	array = string.split('')
	n = array.length
	minimum_hug = 0
	(0...(n / 2)).each_with_index do |i|
		if array[i] != array[n - i - 1]
			minimum_hug += 1
		end
	end
	minimum_hug
end

line = gets.chomp
puts minimum_hug_to_palindrome(line)


Measured memory_bytes: 1916
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        long[] imp = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        long n = imp[0], x = imp[1];
        long[] a = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        long[] a2 = new long[n];
        a2[0] = Math.Min(x, a[0]);
        for (int i = 1; i < n; i++)
            a2[i] = (a2[i - 1] + a[i] <= x) ? a[i] : x - a2[i - 1];
        Console.WriteLine(a.Sum() - a2.Sum());
    }
}

Measured memory_bytes: 32092
#include<cstdio>
#include<algorithm>

using namespace std;

int a[100000];

int main()
{
	for(int n,k;scanf("%d%d",&n,&k),n;){
		int sum=0;
		for(int i=0;i<k-1;i++){
			scanf("%d",a+i);
			sum+=a[i];
		}
		int smax=-1<<31;
		for(int i=k-1;i<n;i++){
			scanf("%d",a+i);
			sum+=a[i];
			smax=max(smax,sum);
			sum-=a[i-k+1];
		}
		printf("%d\n",smax);
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>

using namespace std;

const int mod = 998244353;
int a[200000];
int c[1000001];
int d[1000001];

class inverse {
    public:
    inverse(int n, int mod);
    ~inverse();
    long long get_inv(int x);
    long long get_fact(int x);
    long long get_invfact(int x);
    long long get_comb(int x, int y);
    
    private:
    int mod;
    long long* inv;
    long long* fact;
    long long* invfact;
};

inverse::inverse(int n, int mod) : mod(mod) {
    inv = (long long *)malloc(sizeof(long long) * (n + 1));
    fact = (long long *)malloc(sizeof(long long) * (n + 1));
    invfact = (long long *)malloc(sizeof(long long) * (n + 1));
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    fact[0] = invfact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    for (int i = 1; i <= n; i++) invfact[i] = invfact[i - 1] * inv[i] % mod;
}

inverse::~inverse() {
    free(inv);
    free(fact);
    free(invfact);
}

long long inverse::get_inv(int x) {
    return inv[x];
}

long long inverse::get_fact(int x) {
    return fact[x];
}

long long inverse::get_invfact(int x) {
    return invfact[x];
}

long long inverse::get_comb(int x, int y) {
    return fact[x] * invfact[y] % mod * invfact[x - y] % mod;
}

int main() {
    int n, ans = 0, i, j;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for (i = 0; i < n; i++) c[a[i]]++;
    
    inverse inv(1000000, mod);
    
    for (i = 1; i <= 1000000; i++) d[i] = inv.get_inv(i);
    
    for (i = 1; i <= 1000000; i++) {
        for (j = i * 2; j <= 1000000; j += i) {
            d[j] -= d[i];
            if (d[j] < 0) d[j] += mod;
        }
    }
    
    for (i = 1; i <= 1000000; i++) {
        long long sum1 = 0, sum2 = 0, sum;
        
        for (j = i; j <= 1000000; j += i) {
            sum1 += (long long)j * c[j];
            sum2 += (long long)j * j * c[j];
        }
        
        sum1 %= mod;
        sum2 %= mod;
        sum = sum1 * sum1 % mod - sum2;
        if (sum < 0) sum += mod;
        sum = sum * inv.get_inv(2) % mod;
        ans += d[i] * sum % mod;
        if (ans >= mod) ans -= mod;
    }
    
    printf("%d\n", ans);
    
    return 0;
}


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

using namespace std;

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

int ans[1010100];

int cnt;

int main(){
	int n=read();
	while(n!=0){
		int d=n%(-2);
		n/=(-2);
		if(d==-1){
			n++;
			d=1;
		} 
		cnt++;
		ans[cnt]=d;
	}
	for(int i=cnt;i>=1;i--){
		printf("%d",ans[i]);
	}
	if(cnt==0) cout<<0;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long  xorx(long long  n)
{
    long long   k = (n&3ll);
    if(k == 0ll)
        return n;
    if(k == 1ll)
        return 1ll;
    if(k == 3ll)
        return 0ll;
    if(k == 2ll)
        return (n + 1ll);
}

int  main()
{

   long long  a , b;
   cin >> a >> b;
   long long  first = xorx(a-1);
   long long  second = xorx( b);
   long long  answer = (first ^ second);
   cout << answer << "\n";



return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll A, B, N;
    cin >> A >> B >> N;
    if (N >= (B - 1))
    {
        cout << (A * (B - 1) / B) << endl;
    }
    else
    {
        cout << (A * N) / B << endl;
    }
}

Measured memory_bytes: 3636
/*
=================================
|                               |
|      WE ARE < YN > team       |
|                               |
|   learn more,more and more    |
|                               |
=================================
*/
#include<bits/stdc++.h>
#define fastio std::ios_base::sync_with_stdio(false), std::cout.tie(0), std::cin.tie(0);
#define N 1000007
#define mxx INT_MAX

typedef long long ll;

void solve() {
	int num;
	std::cin>>num;
	std::string name;
	std::cin>>name;
	int n=name.size();
	if(n<=num)std::cout<<name;
	else{
		std::cout<<name.substr(0,num);
		std::cout<<"...";
	}


}
int main() {
	/*int t;
	std::cin >> t;
	while (t--)*/
		solve();
}


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

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

int main(){
  int h,a;
  cin >> h >> a;

  int i = 0;
  while (h > 0) {
    h -= a;
    i++;
  }
  cout << i << endl;
}


Measured memory_bytes: 3480
def main():
	N = int(input())
	A = [int(a) for a in input().split(" ")]
	S = sum(A)
	cA = [0] * 1000001
	for i in range(len(A)):
		cA[A[i]] += 1
	Q = int(input())
	for i in range(Q):
		B, C = [int(x) for x in input().split(" ")]
		diff = (C-B)*cA[B]
		S += diff
		cA[C] += cA[B]
		cA[B] = 0
		print(S)

main()


Measured memory_bytes: 23636
<?php
fscanf(STDIN, '%d %d %d', $cnt, $blue, $red);
$sum = $blue + $red;
$loop = intdiv($cnt, $sum);
$ans = $blue * $loop;
$rest = $cnt - ($loop * $sum);
$ans += min($blue, $rest);
echo $ans;
echo "\n";

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    int OrSum = 0;
    ll Sum = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
        OrSum |= a[i];
        Sum += b[i];
    }
    if(OrSum <= k){
        cout << Sum << endl;
        return 0;
    }
    if(k == 0){
        Sum = 0;
        for(int i = 0; i < n; ++i){
            if(a[i] == 0)   Sum += b[i];
        }
        cout << Sum << endl;
        return 0;
    }

    int MostSignificantBit = 0;
    for(int i = 30; i >= 0; --i){
        if((k >> i) & 1){
            MostSignificantBit = i;
            break;
        }
    }

    ll ans = 0;
    for(int i = 0; i < n; ++i){
        if((k | a[i]) == k) ans += b[i];
    }

    for(int i = MostSignificantBit; i >= 0; --i){
        int val = k;
        if((k >> i) & 1){
            val ^= (1 << i);
            for(int j = i - 1; j >= 0; --j) val |= (1 << j);
        }

        ll foo = 0;
        for(int j = 0; j < n; ++j){
            if((val | a[j]) == val) foo += b[j];
        }

        chmax(ans, foo);
    }

    cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

vii factorize(ll x) {
    vii res;
    ll n = x;
    for (ll p = 2; p*p <= n; p++) {
        if (x%p != 0) continue;
        int count = 0;
        while (x%p == 0) {
            count++;
            x /= p;
        }
        res.push_back(make_pair(p, count));
    }
    if (x != 1) res.push_back(make_pair(x, 1));
    return res;
}

vi getFactors(ll x) {
    vii f = factorize(x);
    vi ret;
    ret.push_back(1);
    for (int i = 0; i < f.size(); i++) {
        int s = ret.size();
        for (int j = 0; j < s; j++) for (int k = 0; k < f[i].second; k++) {
            ret.push_back(ret[j]*pow(f[i].first, k+1));
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

ll N;

ll solve() {
    ll ret = getFactors(N-1).size();
    ret--;
    FORE (x, getFactors(N)) if (x != 1) {
        ll n = N;
        while (n % x == 0) n /= x;
        if (n % x == 1) ret++;
    }
    return ret;
}

int main() {
    cin >> N;
    cout << solve() << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REP(i,a,b) for(ll i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    string S;
    cin >> S;
    ll K,T=1,H=0,C=0;
    cin >> K;
    vector<ll> V;
    rep(i,S.size()){
        if(i<S.size()-1 && S[i]==S[i+1]){
            T++;
        }
        else if(i<S.size()){
            V.pb(T);
            T=1;
        }
        else if(i==S.size()-1){
            V.pb(T);
        }
        if(i==S.size()-1 && S[i]==S[0]){
            H=V[0]+V[V.size()-1];
        }
    }
    if(H>0){
        REP(i,1,V.size()-1){
            C+=V[i]/2;
        }
        if(V.size()>=2){
            cout << C*K+(V[0]/2)+(V[V.size()-1]/2)+(H/2)*(K-1) << endl;
        }
        else{
            cout << S.size()*K/2 << endl;
        }
    }
    else{
        rep(i,V.size()){
            C+=V[i]/2;
        }
        cout << C*K << endl;;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

    int n;
    int b, f, r, v;
    int i, j, m, tmp;
    int data[4][3][10];
    
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(m=0;m<10;m++){
                data[i][j][m] = 0;
            }
        }
    }

    scanf("%d", &n);

    for(tmp=0;tmp<n;tmp++){
        scanf("%d %d %d %d", &b, &f, &r, &v);

        data[b-1][f-1][r-1] += v;
    }

    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(m=0;m<10;m++){
                printf(" %d", data[i][j][m]);
            }
            printf("\n");
        }
            if(i != 3 ){
            printf("####################\n");
}
    }   
    return 0; 
}
    

Measured memory_bytes: 612
num = int(input())
str = list(input())
alp = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
out=""
for i in range(len(str)):
	for l in range(len(alp)):
		if str[i]==alp[l]:
			out+=alp[(l+num)%26]
			break
print(out)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  if(S[2]==S[3]&&S[4]==S[5]){
    cout<<YES<<endl;
  }else{
    cout<<NO<<endl;
  }
}

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


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) { cin >> d[i]; }
    // check
    // rep(i, n) { cout << d[i]; }

    // cout << endl;

    // 処理
    sort(all(d));
    // rep(i, n) { cout << d[i]; }

    // cout << endl;

    int tmp = n / 2;
    int num = 0;
    // cout << d[tmp - 1] << d[tmp] << endl;
    // cout << endl;
    num = d[tmp] - d[tmp - 1];
    cout << num << endl;

    // 出力

    return 0;
}


Measured memory_bytes: 640
/// Author:- Lazy_Coder

#include<bits/stdc++.h>
#define ll long long int
using namespace std;

long computeXOR(const int n)
{

    switch(n & 3)
    {
    case 0: return n;
    case 1: return 1;
    case 2: return n + 1;
    case 3: return 0;
    }
}

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll power(ll x, ll y)
{
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}

int main()
{
    ll r,d,x;
    cin>>r>>d>>x;
    for(int i=1;i<=10;i++)
    {
        x = r*x-d;
        cout<<x<<'\n';
    }
    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,k,x,bil,ans;
bool memo[105];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<=k;i++){
        cin>>x;
        for(int j=1;j<=x;j++){
            cin>>bil;
            memo[bil]=true;
        }
    }    
    for(int i=1;i<=n;i++){
        if(memo[i]==false) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main(){ 
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if (u==s){
        a--;
    }
    else if (u==t){
        b--;
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin >> N;
	vector<ll> x(N),y(N),h(N);
	FOR(i,0,N){
		cin >> x[i] >> y[i] >> h[i];
	}
	FOR(xx,0,101){
		FOR(yy,0,101){
			bool ok=true;
			set<ll> H;
			ll MAXH=INF;
			ll p;
			FOR(i,0,N){
				if(h[i]!=0){
					p = h[i]+abs(xx-x[i])+abs(yy-y[i]);
					H.insert(p);
				}else{
					MAXH=min(MAXH,abs(x[i]-xx)+abs(yy-y[i]));
				}
			}
			if(H.size()>1)ok=false;
			if(p>MAXH)ok=false;
			if(ok){
				cout << xx << " " << yy << " " << p << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
    int A, B, H, M;
    
    cin >> A >> B >> H >> M;

    double theta_a,theta_b;
    double theta,l;

    theta_a = M * M_PI / 30;
    theta_b = H * M_PI / 6 + M * M_PI / 360;

    
    theta = theta_a - theta_b;

    l = sqrt(pow(A,2) + pow(B,2) - 2*A*B*cos(theta));

    cout << fixed << setprecision(20) << l << endl;


    return 0;
}

Measured memory_bytes: 4080
use proconio::input;
use proconio::marker::{Bytes, Chars};

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


fn main() {
    input!{
        x: [usize; 5],
    }
    for i in 0..5 {
        if x[i] == 0 {
            println!("{}", i+1);
        }
    }
}


Measured memory_bytes: 2104
//人正是因为度过了一段阴暗岁月，才会更渴求黎明的曙光
//青春不能回头。所以青春也没有终点。
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <memory.h>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

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

const int MAXN = 0;

int main(void) {
	int N;
	cin >> N;
	cout << N/500*1000+(N-N/500*500)/5*5 << endl;
	return 0;
}




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

#define mp       make_pair
#define mt	 make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF=1<<29;
const double EPS=1e-9;
const ll MOD = 1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int H,W;
int A,B;


/*
fact[0] = fact[1] = 1
inve[0] = inve[1] = 1
for (int i = 2; i <= MAX_N; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
    inve[i] = mod_pow(fact[i], MOD - 2, MOD);//フェルマーの小定理fact[i]とMODが互いにその場合
    }*/
// combinationを求める
//逆元を求めるのでmodが素数の時
const int MAX_N = 500010;
ll fact[MAX_N]; // N!の計算
ll inve[MAX_N]; // N!の逆元
ll mod_pow(ll x, ll n, ll mod) { // x^nをO(logn)で求める
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
ll comb(ll n, ll r) { // nCrを求める
  if (n < r)
    return 0;
  return fact[n] % MOD * inve[n - r] % MOD * inve[r] % MOD;
}
ll f(ll n, ll a, ll b){//n!/(a! * b!)
  if (n < 0 or a < 0 or b < 0){
    return 0;
  }
  return fact[n] % MOD * inve[a] % MOD * inve[b] % MOD;

}
ll result;
int main(){
  result = 0;
  cin >> H >> W >> A >> B;
  fact[0] = fact[1] = 1;
  inve[0] = inve[1] = 1;
  for (int i = 2; i < MAX_N; i++){
    fact[i] = (fact[i - 1] * i) % MOD;
    inve[i] = mod_pow(fact[i], MOD - 2, MOD);
  }
  for (int y = 1; y <= H - A; y++){
    ll rest_h = y - 1;
    ll rest_w = B - 1;
    ll sum = f(rest_h + rest_w, rest_h, rest_w);
    ll last_h = H - (y - 1) - 1;
    ll last_w = W - B - 1;
    result += sum %MOD * f(last_h + last_w, last_h, last_w);
    result %= MOD;
  }
  cout << result << endl;
}


Measured memory_bytes: 8064
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val w, h, x, y, r = sc.nextInt //順番にnextIntで代入されていく
    
    if(r <= x && r <= y && x <= w-r && y <= h-r) println("Yes")
    else println("No")
  }
}


Measured memory_bytes: 44920
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
        int t = sc.nextInt();
        int s = sc.nextInt();
        if(d>(s*t)){System.out.println("No");}
        else{System.out.println("Yes");}
	}
}


Measured memory_bytes: 35620
#include <stdio.h>
#include <ctype.h>
 
int main() {
 
  char ch[1200];
  int i,n;
  n=0;
  char a[1200];
 
  while(1) {
    scanf("%c",&a[n]);
    if(a[n] == '\n') {
      break;
    }
    ch[n] = a[n];
    if('A' <= a[n] && a[n] <= 'Z') {
      ch[n] = a[n] + 32;
    } else if(a[n] >= 'a' && a[n] <= 'z') {
      ch[n] = a[n] - 32;
 
    }
     
     
    n = n +1;
     
  }
   
  for(i=0; i<n ; i++) {
    printf("%c" ,ch[i]);
  }
  printf("\n"); 
  return 0;
   
}


Measured memory_bytes: 2068
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)









int main() {
    int s;
    cin >> s;
    map<int, bool> mp;
    mp[s] = true;
    for(int i = 2;; i++){
        if(s & 1){
            s *= 3;
            s++;
        }
        else{
            s /= 2;
        }
        if(mp[s]){
            cout << i << endl;
            return 0;
        }
        mp[s] = true;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int l,r;
    int count=0;
    for(int i=0; i<N; i++){
        cin >> l >> r;
        count += (r-l+1);
    }
    cout<< count <<endl;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {

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

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m==0)break;
			int[] pos = new int[m];
			
			for(int i=0;i<n;i++){
				for(int j=0;j<m;j++){
					int in = sc.nextInt();
					if(in==1)pos[j]++;
				}
			}
			
			boolean go = true;
			for(int i=n;i>=0;i--){
				for(int j=0;j<m;j++){
					if(pos[j]==i){
						if(go==false)System.out.print(" ");
						System.out.print(j+1);
						go = false;
					}
				}
			}
			System.out.println();
			
		}
	}
}

Measured memory_bytes: 80612
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#include<numeric>
#define rep(a,b) for(ll a=0;a<b;++a)
#define REP(a,b,c,d) for(ll a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	int N, K; cin >> N >> K;
	if ((K - 1) * 2 < N) cout << "YES" << endl;
	else cout << "NO" << endl;
	cin >> N;
}

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    k = len(str(n))
    dp = [0, -INF]

    for c in str(n):
        c = int(c)
        ndp = [-INF, -INF]
        for d in range(10):
            for lt in range(2):
                if not lt and c < d:
                    continue
                nlt = max(lt, c > d)
                ndp[nlt] = max(ndp[nlt], dp[lt] + d)
        dp = ndp

    print(max(dp))
resolve()

Measured memory_bytes: 38384
import numpy as np
n, m = map(int, input().split())
a = []
b = []
ans = 0
for i in range(n):
    a_next, b_next = map(int, input().split())
    a.append(a_next)
    b.append(b_next)

a_sorted_index = np.argsort(a)

for i in range(1000000):
    min_index = a_sorted_index[i]
    if m - b[min_index] <=0:
        break
    m = m - b[min_index]
    ans += a[min_index]*b[min_index]

ans += m * a[min_index]
print(ans)

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


int comM(string str){
  int res = 0;
  int sum = 0;
  if(str.size() == 1) res = str[0]-'0';
  for(int i=0;i<str.size();i++) 
    if(str[i] =='*' && sum == 0) sum += (str[i-1]-'0') * (str[i+1]-'0');
    else if(str[i] =='*' && sum != 0) sum *= (str[i+1] - '0');
    else if(str[i] == '+') res += sum,sum = 0;
  res += sum;
  if(str[1] == '+') res += str[0]-'0';
  for(int i=0;i<str.size();i++) 
    if(str[i] == '+' && (i+1 == str.size()-1||str[i+2] != '*')) res += str[i+1]-'0';
    return res;
} 

int comL(string str) {
  int res = str[0]-'0';
  for(int i=0;i<str.size();i++)
    if(str[i] == '*') res *= (str[i+1]-'0');
    else if(str[i]=='+') res += (str[i+1]-'0');
  return res;
}

int main(){
  string str;
  cin >> str;
  int n;
  cin >> n;
  int M = comM(str);
  int L = comL(str);
  //  cout << M<<endl;
  //cout << L <<endl;
  if(M==n && L == n) cout << "U"<<endl;
  else if(M==n) cout << "M"<<endl;
  else if(L==n) cout <<"L"<<endl;
  else cout << "I"<<endl;
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std; 
#define int int64_t
#define itn int
#define fi first
#define se second 
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  int k,s[20][20]={},p[20],a;
  int ans=0;
  int r[20]={};
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>a;
      s[i][a-1]=1;
    }
  }
  for(int i=0;i<m;i++){
    cin>>p[i];
  }
  for(int i=0;i<(1<<n);i++){
    for(int j=0;j<n;j++){
      if(i&(1<<j)){
	for(int k=0;k<m;k++){
	  if(s[k][j]==1) r[k]++;
	}
      }
    }
    bool f=true;
    for(int j=0;j<m;j++){
      if(r[j]%2!=p[j]){
	f=false;
      }
      r[j]=0;
    }
    if(f) ans++;
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 3656
n = int(input())
s = [input() for _ in range(n)]
valid = True
if len(set(s)) != n:
    valid = False
else:
    for i in range(n - 1):
        if s[i][-1] != s[i + 1][0]:
            valid = False
            break
if valid is False:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 2940
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int N, Q;
    scan(N, Q);
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. N - 1) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= bi;
        adj[bi] ~= ai;
    }

    auto t = new long[](N);
    foreach (i ; 0 .. Q) {
        int pi, xi;
        scan(pi, xi);
        pi--;
        t[pi] += xi;
    }

    auto ans = new long[](N);

    void dfs(int v, int p, long val) {
        val += t[v];
        ans[v] = val;

        foreach (u ; adj[v]) if (u != p) {
            dfs(u, v, val);
        }
    }

    dfs(0, -1, 0);

    writefln("%(%s %)", ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 37372
import itertools

N, M = map(int, input().split())
L = []
res, cnt = 0, 1

for i in range(N):
    K = list(map(int, input().split()))
    L.append(K[1:])

L = list(itertools.chain.from_iterable(L))
L.sort()
L.append(100)

for i in range(len(L)-1):
    if L[i] == L[i+1]:
        cnt += 1
    else:
        if cnt == N:
            res += 1
        cnt = 1
    

print(res)

Measured memory_bytes: 9044
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) a.begin(), a.end()
#define ifnot(a) if (not(a))
#define int long long
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#define dumpl(x) cerr << #x << " = " << (x) << " " << endl;
#else
const bool test = false;
#define dump(x) 
#define dumpl(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
 
template<typename T>
T gcd(T a, T b)
{
  T c;
  while (a != 0) {
    c = a; a = b%a;  b = c;
  }
  return b;
}
 
class Solver {
public:
  int X, Y;

  void solve() {
    cin >> X >> Y;
    int cnt = 0;
    for (int a = X; a <= Y; a *= 2) cnt += 1;
    cout << cnt << endl;
  }
};
 
signed main()
{
  srand(time(NULL));
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {    
  //     auto ptr = new Solver();
  //     ptr->solve();
  //     delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'


Measured memory_bytes: 256
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    a = list(map(int, input().split()))

    #output
    x = a[0]
    for i in range(1, N):
        x = x^a[i]

    c = [x^aa for aa in a]
    for s in c:
        print(int(float(s)), end = " ")

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()


Measured memory_bytes: 31628
def linearSearch(S,t):
    L = S + [t]
    i = 0
    while L[i] != t: i += 1
    if i == len(L)-1: return 0
    else            : return 1

if __name__=='__main__':
    n=input() 
    S=input().split()
    q=input() 
    T=input().split()
    cnt = 0
    for t in T: cnt += linearSearch(S,t)
    print(cnt)

Measured memory_bytes: 8092
K=int(input())
ANS=[i for i in range(1,10)]
i=0
while len(ANS)<=10**5:
  last=str(ANS[i])[-1]
  if last=="0":
    ANS+=[ANS[i]*10,ANS[i]*10+1]
  elif last=="9":
    ANS+=[ANS[i]*10+8,ANS[i]*10+9]
  else:
    ANS+=[ANS[i]*10+int(last)-1,ANS[i]*10+int(last),ANS[i]*10+int(last)+1]
  i+=1  
ans=ANS[K-1]
print(ans)

Measured memory_bytes: 13260