akhauriyash/Code-Regression huggingface dataset:
# 8 Queens Problem

import sys, itertools
input = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000000)

board = [["."]*8 for _ in range(8)]

def diagonal_positions(Q):
    output = set()
    output.add(Q)
    for i in range(8):
        output.add((Q[0] + i, Q[1] + i))
        output.add((Q[0] + i, Q[1] - i))
        output.add((Q[0] - i, Q[1] + i))
        output.add((Q[0] - i, Q[1] - i))
    return output

k = int(input())
row_indices = set(range(8))
col_indices = set(range(8))
Q_positions = set()
NG_positions = set()

for _ in range(k):
    r, c = map(int, input().split())
    row_indices.discard(r)
    col_indices.discard(c)
    Q_positions.add((r,c))
    NG_positions |= diagonal_positions((r,c))

for rows in list(itertools.permutations(row_indices)):
    for cols in list(itertools.permutations(col_indices)):
        Q_positions_tmp = Q_positions.copy()
        NG_positions_tmp = NG_positions.copy()
        putting_Q = set((rows[i], cols[i]) for i in range(8-k))

        for new_Q in putting_Q:
            if new_Q in NG_positions_tmp:
                break
            else:
                Q_positions_tmp.add(new_Q)
                NG_positions_tmp |= diagonal_positions(new_Q)
        else:
            for q in Q_positions_tmp:
                board[q[0]][q[1]] = "Q"
            for i in range(8):
                print("".join(board[i]))
            exit()


Measured memory_bytes: 5824
#include <iostream>

int main()
{

    int n;

    std::cin >> n;

    if (n % 10 == 7 || (n / 10) % 10 == 7 || (n / 100) % 10 == 7)
        std::cout << "Yes" << std::endl;
    else
    {
        std::cout << "No" << std::endl;
    }
  return 0;
}


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

int main()
{
    int x, y;
    
    while(cin >> x >> y){
        if((x == 0) && (y == 0)) break;
        if(x < y) {
            cout << x << ' ' << y << endl;
        }else {
            cout << y << ' ' << x << endl;
        } 
    }
    
    
    return 0;
    
}


Measured memory_bytes: 3072
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[][10] DtoS;
int[10] SS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..M) {
        auto kss = readln.split.to!(int[]);
        foreach (k; kss[1..$]) DtoS[i] ~= k-1;
    }
    auto PS = readln.split.to!(int[]);

    long solve(int i) {
        if (i == N) {
            foreach (j; 0..M) {
                int s;
                foreach (k; DtoS[j]) s = (s + SS[k])%2;
                if (s != PS[j]) return 0;
            }
            return 1;
        } else {
            auto r1 = solve(i+1);
            SS[i] = 1;
            auto r2 = solve(i+1);
            SS[i] = 0;
            return r1 + r2;
        }
    }

    writeln(solve(0));
}

Measured memory_bytes: 256
#![allow(unused_imports, non_snake_case, dead_code)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

struct Combination {
    modulo: u64,
    size: usize,
    fact: Vec<u64>,
    inv_fact: Vec<u64>,
}

impl Combination {
    fn new(size: usize, modulo: u64) -> Self {
        let mut fact = vec![1; size + 1];
        let mut inv_fact = vec![1; size + 1];
        for i in 1..size + 1 {
            fact[i] = fact[i - 1] * i as u64 % modulo;
        }
        inv_fact[size] = Self::modpow(fact[size], modulo - 2, modulo);
        for i in (1..size + 1).rev() {
            inv_fact[i - 1] = inv_fact[i] * i as u64 % modulo;
        }
        Combination {
            modulo,
            size,
            fact,
            inv_fact,
        }
    }
    fn modpow(mut x: u64, mut y: u64, m: u64) -> u64 {
        let mut res: u64 = 1;
        while y > 0 {
            if y & 1 > 0 {
                res = res * x % m;
            }
            x = x * x % m;
            y >>= 1;
        }
        res
    }
    fn modinv(x: u64, m: u64) -> u64 {
        Self::modpow(x, m - 2, m)
    }
    fn nPr(&self, n: usize, r: usize) -> u64 {
        if n < r {
            return 0;
        };
        self.fact[n] * self.inv_fact[n - r] % self.modulo
    }
    fn nCr(&self, n: usize, r: usize) -> u64 {
        if n < r {
            return 0;
        };
        self.fact[n] * self.inv_fact[r] % self.modulo * self.inv_fact[n - r] % self.modulo
    }
}

const MOD: u64 = 1_000_000_007;

#[fastout]
fn main() {
    input! {
        n:usize, k:usize,
        a:[i64; n]
    }
    let mut a = a;
    a.sort();
    let ncr = Combination::new(2_000_000, MOD);
    let mut ans: i64 = 0;
    for i in 0..n {
        ans += ncr.nCr(i, k-1) as i64 * a[i];
        ans += MOD as i64 - ncr.nCr(n-i-1, k-1) as i64 * a[i] % MOD as i64;
        ans %= MOD as i64;
    }
    println!("{}", ans);
}

Measured memory_bytes: 35200
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int p;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(a[i] == 1) p = i;
  }
  if((n-1) % (k-1) == 0)
    cout << (n-1)/(k-1) << endl;
  else
    cout << (n-1)/(k-1)+1 << endl;
  return 0;
}

Measured memory_bytes: 640
n = int(input())
aas = sorted(list(map(int, input().split())))
aas_len = len(aas)
if aas_len == 1:
    print(1)
    exit()
aas_max = aas[-1]
arr = [1]*(aas_max+1)
for i in range(aas_len):
    if arr[aas[i]] == 0:
        continue
    if arr[aas[i]] == 1:
        arr[aas[i]] = 2
    else:
        arr[aas[i]] = 0
        continue
    idx = aas[i]*2
    while idx <= aas_max:
        arr[idx] = 0
        idx += aas[i]
res = 0
for i in aas:
    if arr[i] != 0:
        res += 1
print(res)

Measured memory_bytes: 32184
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>

using namespace std;


const int N = 100010;


int a[N], b[N];

int num[N];


int main()
{
	int n, m;
	
	scanf("%d %d", &n, &m);
	
	int sum = 0;
	
	for (int i = 1; i <= m; i++)
		scanf("%d", &num[i]),
		sum += (num[i] & 1);
	
	if (m == 1)
	{
		if (num[1] == 1)
			puts("1\n1\n1");
		else
			printf("%d \n2 \n%d %d\n", num[1], num[1] - 1, 1);
		return 0;
	}
	if (sum > 2)
		puts("Impossible");
	else
	{
		for (int i = 2; i <= m; i++)
			if (num[i] & 1)
			{
				if (num[1] & 1) swap(num[m], num[i]);
				else swap(num[i], num[1]);
			}
		for (int i = 1; i <= m; i++)
			a[i] = num[i];
		int total = 0;
		if (num[1] > 1) b[++total] = num[1] - 1;
		for (int i = 2; i < m; i++)
			b[++total] = num[i];
		b[++total] = num[m] + 1;
		for (int i = 1; i <= m; i++)
			printf("%d ", a[i]);
		puts("");
		printf("%d\n", total);
		for (int i = 1; i <= total; i++)
			printf("%d ", b[i]);
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

			if (a % 1000 == 0) {
				System.out.println(0);
			} else {
				System.out.println(1000 - (a % 1000));
			}
		}
	}
}


Measured memory_bytes: 35812
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	ll n, m;
	cin >> n >> m;
	if (n > m) {
		swap(n, m);
	}
	if (n >= 2) {
		cout << (n - 2) * (m - 2) << endl;
	} else {
		if (m >= 2) {
			cout << (m - 2) << endl;
		} else {
			cout << 1 << endl;
		}
	}
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



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

int I[256];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n)scanf("%d", &I[i]);
		int S, A, C;
		double Min = INFINITY;
		rep(s, 16)rep(a, 16)rep(c, 16) {
			int r = s;
			unordered_map<int, int>mp;
			rep(i, n) {
				r = (a*r + c) % MOD;
				mp[(I[i] + r) % MOD]++;
			}
			double sum = 0;
			for (auto p : mp) {
				double d = p.second / double(n);
				sum -= d * log10(d);
			}
			if (Min > sum + 1e-10) {
				Min = sum; S = s; A = a; C = c;
			}
		}
		printf("%d %d %d\n", S, A, C);
	}
}

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

using namespace std;
typedef long long ll;

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

    ll m = 10000000000000000;
    for (int i = 0; i < 5; i++){
        ll temp;
        cin >> temp;
        m = min(m, temp);
    }
    ll cnt = 4ll + (n + m - 1) / m;

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  int now = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'I') now++; else now--;
    ans = max(ans, now);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

static const int NIL = -1;
struct node {
  int p;
  int r;
  int l;
};

node tree[9999];


int depth(int u){
  int d = 0;
  while(tree[u].p != NIL){
    u = tree[u].p;
    d++;
  }
return d;
}

int printh(int u){
  int h1 ,h2;
  h1 = h2 = 0;
  if(tree[u].l != NIL) h1 = printh(tree[u].l) + 1;
  if(tree[u].r != NIL) h2 = printh(tree[u].r) + 1;
  return max(h1 , h2);
}


int printsib(int u){
  int c;
  if(tree[u].p != NIL) c = tree[u].p;
  else return NIL;
  if(tree[c].r != u && tree[c].r != NIL) return tree[c].r;
  else if(tree[c].l != u && tree[c].l != NIL) return tree[c].l;
  else return NIL;
}

int printdeg(int u){
  if(tree[u].r != NIL && tree[u].l != NIL) return 2;
  else if((tree[u].r != NIL && tree[u].l == NIL) || (tree[u].r == NIL && tree[u].l != NIL)) return 1;
  else return 0;
}


void print(int u){
  cout << "node " << u << ": " << "parent" << " = " << tree[u].p << ", " << "sibling" << " = " << printsib(u) << ", " ;
  cout << "degree" << " = " << printdeg(u) << ", " << "depth" << " = " << depth(u) << ", " << "height" << " = " << printh(u) << ", " ;
  if(tree[u].r == NIL && tree[u].l == NIL && tree[u].p != NIL) cout << "leaf" << endl;
  else if(tree[u].p == NIL) cout << "root" << endl;
  else cout << "internal node" << endl;
}

int main(){

  int n,u,c1,c2;
  cin >> n;
  for(int i = 0;i < n;i++) tree[i].p = tree[i].r = tree[i].l = -1;
  for(int i = 0;i < n;i++){
    cin >> u ;
    cin >> tree[u].l >> tree[u].r;
    c1 = tree[u].l;
    c2 = tree[u].r;
    if( c1 != NIL ) tree[c1].p = u;
    if( c2 != NIL ) tree[c2].p = u;
  }

for(int i = 0;i < n;i++) print(i);

}

Measured memory_bytes: 3072
using System;
using System.Collections.Generic;

namespace Project
{
	class Task
	{
		public string name;
		public int time;
	}

	class MainClass
	{
		public static void Main(string[] args)
		{
			int n, q;
			string[] s = Console.ReadLine().Split(' ');
			n = int.Parse(s[0]);
			q = int.Parse(s[1]);
			Queue<Task> task = new Queue<Task>();
			Queue<Task> finished = new Queue<Task>();
			for (int i = 0; i < n; i++)
			{
				s = Console.ReadLine().Split(' ');
				Task tmptask = new Task();
				tmptask.name = s[0];
				tmptask.time = int.Parse(s[1]);
				task.Enqueue(tmptask);
			}
			int time = 0;
			while (task.Count != 0)
			{
				Task tmptask = task.Dequeue();
				if (tmptask.time > q)
				{
					tmptask.time -= q;
					task.Enqueue(tmptask);
					time += q;
				}
				else
				{
					time += tmptask.time;
					tmptask.time = time;
					finished.Enqueue(tmptask);
				}
			}
			while (finished.Count != 0)
			{
				Task tmptask = finished.Dequeue();
				Console.WriteLine("{0} {1}", tmptask.name, tmptask.time);
			}
		}
	}
}

Measured memory_bytes: 18812
Imports System.Console
Module Module1
    Dim ans As Integer
    Sub Main()
        Dim s1() As String = ReadLine().Split
        Dim n, k As Integer
        n = s1(0)
        k = s1(1)
        Dim s2() As String = ReadLine().Split
        Dim A(n) As Integer
        For i = 0 To n - 1
            A(i + 1) = s2(i)
        Next
        For i = 1 To n - k
            If A(k + i) / A(i) > 1 Then
                WriteLine("Yes")
            Else
                WriteLine("No")
            End If
        Next
    End Sub
End Module


Measured memory_bytes: 47020
import java.io.*;
import java.util.*;


public class Main{ 

	public static void main(String args[]){
		
		Scanner scan = new Scanner(System.in);
		Dice d01 = new Dice(scan.nextLine());
		Dice d02 = new Dice(scan.nextLine());
		if(d01.equals(d02))
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}
class Dice{
	int top;
	int back;
	int right;
	int left;
	int front;
	int bottom;
	public Dice(String line){
		String[] face = line.split(" ");
		top = Integer.parseInt(face[0]);
		back = Integer.parseInt(face[1]);
		right = Integer.parseInt(face[2]);		
		left = Integer.parseInt(face[3]);
		front = Integer.parseInt(face[4]);
		bottom = Integer.parseInt(face[5]);
	}
	void rotate(){
		int tmp = front;
		front = right;
		right=back;
		back = left;
		left = tmp;
	}
	public void roll(char c){
		int tmp = top;
		switch(c){
			case 'N':
				top = back;
				back=bottom;
				bottom = front;
				front = tmp;
				break;
			case 'E':
				top = left;
				left = bottom;
				bottom = right;
				right = tmp;
				break;
			case 'S':
				top = front;
				front = bottom;
				bottom = back;
				back = tmp;
				break;
			case 'W':
				top = right;
				right = bottom;
				bottom = left;
				left = tmp;
				break;
		}
	}
	boolean equalFace(Dice d){
		if(this.top == d.top && 
		   this.bottom==d.bottom &&
		   this.right == d.right &&
		   this.left == d.left &&
		   this.front == d.front &&
		   this.back == d.back)
			return true;
		else
			return false;
	}
	@Override
	public int hashCode() {
	    final int prime = 31;
	    int result = 1;
	    result = prime * result + top;
	    result = prime * result +bottom;
	    result = prime * result + right;
	    result = prime * result + left;
	    result = prime * result + front;
	    result = prime * result + back;
	    return result;
    }
	@Override
	public boolean equals(Object obj) {
		Dice d = (Dice) obj;
		return rollAllPattern(d);
	}
	public boolean rotateCheck(Dice d){
		for(int j=0;j<4;j++){
			rotate();
			if(this.equalFace(d))
				return true;
		}
		return false;
	}
	public boolean rollAllPattern(Dice d){
		for(int i=0; i<4;i++){
			roll('N');
			if(rotateCheck(d))
				return true;
		}
		roll('W');
		if(rotateCheck(d))
			return true;		
		roll('E');
		roll('E');		
		if(rotateCheck(d))
			return true;	
		return false;			
	}
	
}	
	
	

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

int main(){

string S;
cin >> S;
int ans = 999;
      for(int i = 0; i <= S.size() - 3; i++){ 
           int num = (S[i] - '0') * 100 + (S[i+1] - '0') * 10 + S[i+2] - '0'; //　"1" - '0'で数字に変換
            ans = min(ans, abs(num - 753));

      }
cout << ans << endl; 
}

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

using namespace std;

int main() {
	int x, n;

	cin >> x >> n;

	vector <int> p(n), a(101, 0);

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

	int right = 101;
	int left = 0;

	for (int i = x; i <= 100; i++) {
		if (!a[i]) {
			right = i;
			break;
		}
	}

	for (int i = x; i >= 0; i--) {
		if (!a[i]) {
			left = i;
			break;
		}
	}

	int ans = -1;

	if (abs(x-left) == abs(x-right)) {
		ans = min(left, right);
	} else if (abs(x-left) < abs(x-right)) {
		ans = left;
	} else if (abs(x-left) > abs(x-right)) {
		ans = right;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3628
package main

import "fmt"

func main() {
	var k, a, b int
	fmt.Scan(&k)
	fmt.Scan(&a, &b)
	for i := a; i <= b; i++ {
		if i%k == 0 {
			fmt.Println("OK")
			break
		}
		if i == b {
			if i%k != 0 {
				fmt.Println("NG")
			}
		}
	}
}


Measured memory_bytes: 1752
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct t_xy{
	int				x;
	int				y;
	// struct t_xy	*next;
}					s_xy;

int	ft_iterative_factorial(int nb)
{
	int	n;

	n = nb - 1;
	while (n)
	{
		nb *= n;
		n--;
	}
	return (nb);
}

int		main()
{
	s_xy	*p, *before;
	int		N, n, x, y, i, k;
	double	sum, ans;

	ans = 0;
	scanf("%d\n", &N);
	// n = ft_iterative_factorial(N - 2);
	// n = ft_iterative_factorial(N - 1) * ft_iterative_factorial(N - 2);
	// N! * (N - 1) / ((N * (N - 1)) / (N - 1)!)
	p = (s_xy *)malloc(sizeof(s_xy) * (N + 1));
	i = 0;
	while (i < N)
	{
		scanf("%d %d\n", &p[i].x, &p[i].y);
		i++;
	}
	i = 0;
	while (i < (N - 1))
	{
		k = i + 1;
		while (k < N)
		{
			sum = 0;
			sum = pow((p[i].x - p[k].x), 2.0);
			sum += pow((p[i].y - p[k].y), 2.0);
			ans += sqrt(sum);
			k++;
			// printf("%d: sum = %f\n", i, sum);
		}
		i++;
	}
	// printf("%f\n", ans);

	// ans *= (double)n;
	// ans /= (double)ft_iterative_factorial(N);
	ans *= 2.0 / (double)N;
	printf("%.10f\n", ans);

	return (0);
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int n,m,l;
	scanf("%d%d%d",&n,&m,&l);
	int i,j,k;
	int a[100][100],b[100][100];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			scanf("%d",&b[i][j]);
		}
	}
	long sum=0;
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			for(k=0;k<m;k++){
				sum+=a[i][k]*b[k][j];
			}
			if(j==l-1){
				printf("%ld\n",sum);
				sum=0;
				continue;
			}
			printf("%ld ",sum);
			sum=0;
		}
	}
	return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
#define N 100000
int partition(int, int);
int A[N];
int main(){
  int n,a,i;
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%d",&A[i]);
  }
  a=partition(0,n-1);
  for(i=0;i<n;i++){
    if(i>0){
      printf(" ");
    }if(i==a){
      printf("[%d]",A[i]);
    }
    else {
      printf("%d",A[i]);
    }
  }
  printf("\n");

  return 0;
}

int partition(int a, int r){
  int x,i,k,cn;
  x=A[r];
  cn=a-1;
  for(i=a;i<r;i++){
    if(A[i]<=x){
      cn++;
      k=A[cn];
      A[cn]=A[i];
      A[i]=k;
    }
  }

  k=A[cn+1];
  A[cn+1]=A[r];
  A[r]=k;

  return cn+1;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,m;
    cin>>n>>m;
    ve <bool> isred(n+1,false);
    ve <ll> box_size(n+1,1);
    isred[1]=true;
    while(m--)
    {
        ll x,y;
        cin>>x>>y;
        box_size[x]--;
        box_size[y]++;
        if (isred[x])
        {
            isred[y]=true;
        }
        if (box_size[x]==0)
        {
            isred[x]=false;
        }
    } 
    ll cnt=0;
    rep (i,1,n+1)
    {
        if (isred[i]&&box_size[i]>0)
        {
            cnt++;
        }
    }
    cout<<cnt<<"\n";
}


Measured memory_bytes: 3960
#include <stdio.h>

int main(){
    int N,i,old_index,result;
    int A[100],B[100],C[100];

    old_index = -1;
    result = 0;
    scanf("%d",&N);

    for(i = 1 ; i < N+1 ; i++){
        scanf("%d",&A[i]);
    }
    for(i = 1 ; i < N+1 ; i++){
        scanf("%d",&B[i]);
    }
    for(i = 1 ; i < N ; i++){
        scanf("%d",&C[i]);
    }

    for(i = 1 ; i < N + 1 ; i++){
        result += B[A[i]];
        //printf("%d点もらいました\n",B[A[i]]);
        if((A[i] - old_index) == 1){
            result += C[old_index];
            //printf("追加で%dもらいました\n",C[old_index]);
        }
        old_index = A[i];
    }
    printf("%d",result);

    return 0;

}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;


public class Main {
	
	public static class Range implements Comparable<Range> {
		long x, l;
		
		public Range (long x, long l) {
			this.x = x;
			this.l = l;
		}

		@Override
		public int compareTo(Range o) {
			return Long.compare(this.x + this.l, o.x + o.l);
		}
	}
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] xs = new long[N];
			long[] ls = new long[N];
			Range[] ranges = new Range[N];
			
			for(int i = 0; i < N; i++) {
				xs[i] = sc.nextLong();
				ls[i] = sc.nextLong();
				
				ranges[i] = new Range(xs[i], ls[i]);
			}
			
			Arrays.sort(ranges);
			
			
			int answer = 0;
			long prev = Long.MIN_VALUE;
			for(final Range range: ranges) {
				final long l = range.x - range.l;
				
				// System.out.println(prev + " " + l);
				if(prev <= l) {
					answer += 1;
					prev = range.x + range.l;
				}
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 49772
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    double a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << a * b / 2 << " ";
    int res = 0;
    if(a == c * 2 and b == d * 2)res = 1;
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5005,mod=1e9+7;
int n,a,b;
ll f[N],c[N][N],dp[N][2];
ll C(int n,int m)
{
    if(m==0||n==m) return 1;
    if(m==1) return n;
    if(c[n][m]) return c[n][m];
    return c[n][m]=(C(n-1,m-1)+C(n-1,m))%mod;
}
ll qpow(ll a,ll n)
{
    ll ans=1;
    for(;n;n>>=1,a=a*a%mod)if(n&1) ans=ans*a%mod;
    return ans;
}
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    if(a>b) swap(a,b);
    f[1]=1;
    for(int i=1;i<b;i++)
    {
        f[i+1]=(f[i+1]+f[i])%mod;
        for(int j=a;i+j+1<=b;j++)
                f[i+j+1]=(f[i+j+1]+f[i])%mod;
    }
    dp[0][0]=dp[0][1]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<i+a&&j<=n;j++)
            (dp[j][0]+=dp[i][1])%=mod;
        for(int j=i+1;j<i+b&&j<=n;j++)
            (dp[j][1]+=dp[i][0]*f[j-i+(i==0||j==n)])%=mod;
    }
    ll ans=qpow(2,n);
    ans=(ans-dp[n][0]-dp[n][1])%mod;
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 3916
// C - Welcome to AtCoder
#include <bits/stdc++.h>
using namespace std;

int wa_count[100000];

int main(){
	int n,m,p,ac=0,wa=0;
	char s[3];
	scanf("%d%d",&n,&m);
	while(m--){
		scanf("%d%s",&p,s); --p;
		if(wa_count[p] >= 0)// not ac
			if(s[0] == 'W') wa_count[p]++;
			else{
				ac++;
				wa += wa_count[p];
				wa_count[p] = -1;// ac flag on
			}
	}
	printf("%d %d\n",ac,wa);
}

Measured memory_bytes: 640
from math import factorial
def c(n,k):
  return factorial(n)//factorial(k)//factorial(n-k)
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd=0
for i in a:
  if i%2==1:
    odd+=1
even = n-odd
m = (odd // 2) + 1
even_ = pow(2,even)
odd_ = 0
for i in range(m):
  odd_ += c(odd,i*2)
if p==0:
  print(even_ * odd_)
else:
  print(pow(2,n)-even_ * odd_)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_set>

using namespace std;
const int inf = 1e9;

int main() {
	int n, m, b, tmp;
	cin >> n >> m;

	vector<int> a(m, 0);
	vector<int> c(m, 0);

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

		for (int j = 0; j < b; j++) {
			cin >> tmp;
			tmp--;
			c[i] |= (1 << tmp);
		}
	}

	int limit = (1 << n);
	vector<vector<int>> dp(m + 1, vector<int>(limit, inf));
	for (int i = 0; i < dp.size(); i++) {
		dp[i][0] = 0;
	}


	for (int i = 0; i < m; i++) {
		for (int j = 0; j < limit; j++) {
			int cost = dp[i][j];

			// printf("ij %d %d: cost %d\n", i, j, cost);

			if (cost == inf) {
				continue;
			}

			// 買わない
			dp[i+1][j] = min(dp[i+1][j], cost);

			// 買う
			int cost2 = cost + a[i];
			int nums = j | c[i];
			dp[i+1][nums] = min(dp[i+1][nums], cost2);
		}
	}

	// for (int j = 0; j < limit; j++) {
	// 		int cost = dp[m][j];
	// 	printf("ij %d %d: cost %d\n", m, j, cost);
	// }

	int ans = dp[m][limit - 1];

	if (ans == inf) {
		ans = -1;
	}

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


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

int main(){
	int64_t a, b, c, d, e, ans = 0;
	cin >> a >> b >> c >> d >> e;
	e *= 100;
	ans += min({e / 200 * d, e / 200 * 2 * c, e / 200 * 4 * b, e / 200 * 8 * a});
	e %= 200;
	ans += min({e / 100 * c, e / 100 * 2 * b, e / 100 * 4 * a});
	e %= 100;
	ans += min({e / 50 * b, e / 50 * 2 * a});
	e %= 50;
	ans += e / 25 * a;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int c=0;
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-i-1]){
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
open Batteries

module Intmap = Map.Make(Int)

let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let intmap = Intmap.empty in
  let intmap = List.fold_left (fun accum x -> Intmap.modify_opt x (fun v_opt -> match v_opt with
        Some v -> Some (v+1)
      | None -> Some 1
    ) accum) intmap a_lst
  in
  let assoc = Intmap.bindings intmap in
  let ans = List.map (fun (i,c) -> if i < c then c-i else if i > c then c else 0) assoc |> List.fold_left (+) 0 in

  Printf.printf "%d\n" ans


Measured memory_bytes: 15488
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	int N, M;
	cin >> N >> M;

	vector<vector<int>> a( N, {0, 1} );
	a[0][0] = 1;
	a[0][1] = 0;

	for( int i = 0; i < M; ++i ) {
		int x, y;
		cin >> x >> y;
		x -= 1;
		y -= 1;

		if( a[x][0] ) {
			if( a[x][1] > 0 ) {
				a[x][1] -= 1;
				if( a[y][0] ) {
					a[y][1] += 1;
				}
				else {
					a[y][0] = 1;
				}
			}
			else {
				a[x][0] = 0;
				if( a[y][0] ) {
					a[y][1] += 1;
				}
				else {
					a[y][0] = 1;
				}
			}
		}
		else {
			a[x][1] -= 1;
			a[y][1] += 1;
		}
	}

	int ans = 0;
	for( int i = 0; i < N; ++i ) {
		ans += a[i][0];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5760
#include<iostream>
using namespace std;
typedef long long ll;
ll num[100005];
int main(){
	ll N,t=0;
	cin>>N;
	ll sum=0;
	for(int i=0;i<N;i++){
		cin>>num[i];
		sum=sum+abs(num[i]-t);
		t=num[i];
	}
	//下面开始丢弃数据
	for(int i=0;i<N;i++){
		int ans=sum;
		if(i!=0||i!=N-1){
			ans=ans-abs(num[i]-num[i-1])-abs(num[i+1]-num[i])+abs(num[i+1]-num[i-1])+abs(num[N-1]-0);
		}else if(i==0){
			ans=ans-abs(num[i]-0)-abs(num[i+1]-num[i])+abs(num[i+1]-0)+abs(num[N-1]-0);
		}else{
			ans=ans-abs(num[i]-num[i-1])+abs(num[i-1]-0);
		}
		cout<<ans<<endl;
	} 
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
long long s[100000],f[100000];
int main(){
	long long n,a,b,k,p,q=0;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	cin>>s[i];
	for(int i=1;i<n;i++)
	{
		k=s[i+1]-s[i];
		p=k*a;
		if(p>b)
		{
			f[i]=b;
		}
		else f[i]=p;
	}
	for(int i=1;i<n;i++)
	q+=f[i];
	cout<<q<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int la,hh,n,A,B,i,j,a[500001];
int main(){
	scanf("%d%d%d",&n,&A,&B);
	if(B+A>n+1)return puts("-1"),0;
	if((ll)B*A<(ll)n)return puts("-1"),0;
	for(i=B;i;i--)printf("%d ",i);
	la=B;
	for(i=2;i<A;i++){
		hh=min(B,n-la-(A-i));
		for(j=hh+la;j>la;j--)printf("%d ",j);
		la+=hh;
	}
	for(i=n;i>la;i--)printf("%d ",i);
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int mod = 1000000007;
  ll dp[n+1][4];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i=0; i<n; i++) {
    for (int j=0; j<4; j++) {
      if (s[i] != '?') dp[i+1][j] += dp[i][j] % mod;
      else dp[i+1][j] += dp[i][j] * 3 % mod;
      dp[i+1][j] %= mod;
    }
    if(s[i] == '?' || s[i] == 'A') {
      dp[i+1][1] += dp[i][0] % mod;
      dp[i+1][1] %= mod;
    }
    if(s[i] == '?' || s[i] == 'B') {
      dp[i+1][2] += dp[i][1] % mod;
      dp[i+1][2] %= mod;
    }
    if(s[i] == '?' || s[i] == 'C') {
      dp[i+1][3] += dp[i][2] % mod;
      dp[i+1][3] %= mod;
    }
  }
  cout << dp[n][3] << endl;
}


Measured memory_bytes: 3584
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int A,B,K;
  cin >> A >> B >> K;
  int check=0;
  rep(i,K) if(A+i<=B) cout << A+i << endl,check=A+i;
  for(int i=B-K+1;i<=B;i++) if(i>check) cout << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int MAX_N = 100050;
const ll MOD = 1e9+7;
string s;
int n;

ll cache[MAX_N][2];

ll solve(int pos, int flag) {
	if(pos == n) {
		return 1;
	}

	ll& ret = cache[pos][flag];
	if(ret != -1) return ret;
	ret = 1;

	if(flag) {
		return ret = 3 * solve(pos+1, flag) % MOD;
	} else {
		if(s[pos] == '0') {
			return ret = solve(pos+1, flag);
		} else {
			ret = solve(pos+1, 1) + 2 * solve(pos+1, flag);
			return ret %= MOD;
		}
	}
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> s;
	n = s.size();
	rep(i,0,MAX_N) rep(j,0,2) cache[i][j] = -1;
	cout << solve(0, 0) << endl;
	return 0;
}


Measured memory_bytes: 5200
#include<stdio.h>
int main(void) {
	int cont1, cont2;
	int A, B, C;
	scanf("%d %d %d",&A,&B,&C);
	int i;
	cont1 = B;
	cont2 = C;
	if (A <= B) {
		printf("%d", cont2);
	}
	else {
		for (i = 1; i <= C; i++) {
			cont2 -= 1;
			cont1 += 1;
			if (cont1 == A || cont2 == 0) break;
		}
		printf("%d", cont2);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n;
	cin>>n;
	ll S=sqrt(n);
	while(n%S!=0){
		S--;
	}
	ll ans=n/S;
	ll ans1=0;
	while(ans!=0){
		ans=ans/10;
		ans1++;
	}
	cout <<ans1;
}

Measured memory_bytes: 384
from collections import Counter

n = int(input())
a = list(map(int,input().split()))

#table = set(a)
con = Counter(a)
dic = {}
#for i in table:
#    con[i] = a.count(i)
#    dic[i] = -1

for x in a:
    if x not in dic:
        ex = (con[x] - 1) * (con[x] - 2) / 2
        no = (con[x]) * (con[x] - 1) / 2
        dic[x] = (int(no), int(ex))

su = sum([int(x[0]) for x in dic.values()])

for i,x in enumerate(a):
    print(su - (dic[x][0] - dic[x][1]))


Measured memory_bytes: 39112
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;} // if(a%b == 0) (a/b) + 1
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0
template<typename T> void vecdbg(vector<T>& v){ rep(i, v.size()){cout << v[i] << " ";} br;}
template<typename T> void vecvecdbg(vector<vector<T>>& v){ rep(i, v.size()){rep(j, v[i].size()){cout << v[i][j] << " ";} br;}}

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    vector<long long> vec(n);
    ll sum = 0;
    for(long long i = 0; i < n; i ++){
        cin >> vec[i];
        sum += vec[i];
    }

    ll ans = 0;
    for(ll i = 0; i < n-1; i++){
        sum -= vec[i];
        ll tmp = ((sum%MOD) * vec[i]) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;
    /*
    ll ans = 0;
    for(ll i = 0; i < n; i ++){
        for(ll j = i+1; j < n; j++){
            ll tmp = (vec[i] * vec[j]) % MOD;
            ans = (ans + tmp) % MOD;
        }
    }
    cout << ans << endl;
    */

}

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

int main() {
  int X;
  string S;
  cin >> S;
  X = 0;
  for(int i=0;i < 4;i++){
    if(S.at(i) == '+')
      X++;
      else
        X--;
      }
  cout << X << endl;
}


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  vector<int> x(n);
  vector<int> y(n);
  rep(i, n) {
    int tt, xx, yy;
    cin >> tt >> xx >> yy;
    t[i] = tt;
    x[i] = xx;
    y[i] = yy;
  }
  int ct = 0;
  int cx = 0;
  int cy = 0;
  bool ok = true;
  for (int i = 0; i < n; ++i) {
    int dt = abs(t[i] - ct);
    int dx = abs(x[i] - cx);
    int dy = abs(y[i] - cy);
    int dist = dx + dy;
    if (!(dt == dist || (dt > dist && ((dt - dist) % 2 == 0)))) {
      ok = false;
      break;
    }
    ct = t[i];
    cx = x[i];
    cy = y[i];
  }
  string res = ok ? "Yes" : "No";
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
 set<ll>m1,m2;
void cdm1(ll n){
    m1.insert(n);
    for(ll i=2;i*i<=n;i++){
        ll nn=n;
        if(nn%i==0){
            m1.insert(i);
            nn/=i;
            m1.insert(nn);
        }
    }
}
void cdm2(ll n){
    m2.insert(n);
    for(ll i=2;i*i<=n;i++){
        ll nn=n;
        if(nn%i==0){
            m2.insert(i);
            nn/=i;
            m2.insert(nn);
        }
    }
}
int main(){
    ll n;cin>>n;
    cdm1(n-1);
    cdm2(n);
    ///////n-1type///////
    ll cnt1=m1.size();
  if(n==2)cnt1=0;
    ///////ntype////////
    ll cnt2=0;
    auto itr2=m2.begin();
    rep(i,m2.size()){
        ll nn=n;
        while(nn%(*itr2)==0){
            nn/=*itr2;
        }
        nn=nn-nn/(*itr2)*(*itr2);
        if(nn==1)cnt2++;
        itr2++;
    }
    cout<<cnt1+cnt2<<endl;
}

Measured memory_bytes: 512
def f(n):
    s, a = 0, n
    while n > 0:
        s += n % 10
        n //= 10

    return a / s


def main():
    snuke = []
    base = 1

    for i in range(15):
        for j in range(1, 140):
            snuke.append(base*(j+1)-1)
        base *= 10

    snuke.sort()
    snuke.append(0)

    snuke2 = []
    for i in range(len(snuke)-1):
        if snuke[i] != snuke[i+1]:
            snuke2.append(snuke[i])

    k, idx, t = int(input()), 0, 0
    while t < k:
        for i in range(idx+1, len(snuke2)):
            if f(snuke2[idx]) > f(snuke2[i]):
                idx += 1
                break
        else:
            print(snuke2[idx])
            t += 1
            idx += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <stdio.h>

int main() {
    int a, b, c, temp;
    scanf("%d %d %d", &a, &b, &c);
    temp = b;
    b = a;
    a = temp;
    temp = c;
    c = a;
    a = temp;
    printf("%d %d %d\n", a, b, c); 
}

Measured memory_bytes: 1708
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

map<ll, int> prime_factor(ll n) {
  map<ll, int> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i) continue;
    res[i] = 0;
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll max_v = gcd(A, B);
  auto primes = prime_factor(max_v);
  cout << primes.size() + 1 << endl;
  return 0;
}

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

int main() {
	long long n, m;
	cin >> n >> m;
	
	vector <pair <long long, long long> > p(n + m);

	for(long long i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}

	for(long long i = n; i < n + m; i++) {
		cin >> p[i].first >> p[i].second;
	}

	for(long long i = 0; i < n; i++) {
		long long ans = n, val = abs(p[i].first - p[n].first) + abs(p[i].second - p[n].second);
		for(long long j = n; j < n + m; j++) {
			long long temp = abs(p[i].first - p[j].first) + abs(p[i].second - p[j].second);
			if(temp < val) {
				val = temp;
				ans = j;
			}
		}
		cout << ans - n + 1<< endl;
	}

	return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (!A.at(i)) return cout << 0 << "\n", 0;
  }
  long ans = 1;
  for (int i = 0; i < N; i++) {
    if ((long double) ans * A.at(i) > 1e18) return cout << -1 << "\n", 0;
    ans *= A.at(i);
  }
  cout << ans << "\n";
}

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

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

  bool flg = true;
  while (flg) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 != 0) {
        flg = false;
        break;
      }
      a[i] /= 2;
    }
    if(flg) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n, m, k;
  scanf("%d", &n);
  m=n%100;
  k=m%10;
  if(k==3){
    printf("bon");
  }
  else if(k==0 || k==1 || k==6 || k==8){
    printf("pon");
  }
  else{
    printf("hon");
  }
  return 0;
}
  


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

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

    string ans;
    if (R < 1200) {
        ans = "ABC";
    } else if (R < 2800) {
        ans = "ARC";
    } else {
        ans = "AGC";
    }
    cout << ans << endl;

    return 0;
}

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

/* */

int main(){

    int n, m, sum;
    cin >> n >> m ;
    sum = 0;
    // **************************************
    int a;
    for(int i=0; i<m; i++) {
        cin >> a;
        sum += a;
    }
    // **************************************
    
    if(n - sum >= 0){
        cout << n-sum << endl;
    }else{
        cout << -1 << endl;
    }


    return 0;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e16;

/*
<url:https://beta.atcoder.jp/contests/abc063/tasks/arc075_a>
問題文============================================================

 （略）
 
=================================================================

解説=============================================================

 合計が10の倍数になったらその合計は０と判断される
 
 先にs1~snまでの総和を求めておく、
 ここで総和が10の倍数でなければ、それが答え
 
 10の倍数であれば、
 s1~snまでの中で一番小さく10の倍数でない数字を一つだけ引けば
 その総和は10の倍数でなくなるので、順番にs1~snを見ていけば良い
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> s(N);
    for(auto &in:s) cin >> in;
    sort(s.begin(),s.end());
    ll sum = 0;
    for(auto v:s) sum += v;
    ll ans = 0;
    if(sum % 10 != 0){
        ans = max(ans,sum);
    }
    for(auto v:s){
        if((sum - v)%10 != 0){
            ans = max(ans,sum - v);
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
MOD = 10 ** 9+7
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
a = lmi()
cnt = 0

for num, i in enumerate(a):
    if a[i-1] == num+1:
        cnt += 1

print(cnt//2)

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

int a[100], b[100], c[100], d[100];

int n;
struct edge {int to, rev; bool valid;};
vector<edge> G[202];
bool used[202];

void add_edge(int from, int to) {
	G[from].push_back({to, G[to].size(), true});
	G[to].push_back({from, G[from].size()-1, false});
}

bool dfs(int v) {
	used[v] = true;
	if(v == 2*n+1) return true;
	for(int i=0;i<G[v].size();i++) {
		edge e = G[v][i];
		if(e.valid && !used[e.to]) {
			bool r = dfs(e.to);
			if(r) {
				G[v][i].valid = false;
				G[e.to][e.rev].valid = true;
				return true;
			}
		}
	}
	return false;
}

int solve() {
	for(int sum = 0;;sum++) {
		for(int i=0;i<2*n+2;i++) used[i] = false;
		bool r = dfs(0);
		if(!r) return sum;
	}
}

int main() {
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
	}
	for(int i=0;i<n;i++) {
		cin >> c[i] >> d[i];
	}
	for(int i=0;i<n;i++) {
		add_edge(0, i+1);
		add_edge(i+n+1, 2*n+1);
	}
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) {
		if(a[i] < c[j] && b[i] < d[j]) add_edge(i+1, j+n+1);
	}
	cout << solve() << endl;
}


Measured memory_bytes: 384