akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define P 998244353

using namespace std;

long long k, n, A, B;

long long modP[300010], fact[300010];

long pow_modulo(long long base, long long exponent)
{
    if (exponent == 0)
        return 1;
    if (exponent == 1)
        return base;
    long long q = pow_modulo(base, exponent / 2);
    if (exponent % 2 == 0)
        return (q * q) % P;
    else return (((q * q) % P) * base) % P;
}

void init()
{
    fact[0] = 1;
    modP[0] = 1;
    for (long long i = 1; i <= 300005; i++)
    {
        fact[i] = (fact[i - 1] * i) % P;
        modP[i] = pow_modulo(fact[i], P - 2);
    }
}

long long combi(long long n, long long k)
{
    if (n < k)
        return 0;
    return (fact[n] * modP[k] % P) * modP[n - k] % P;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cin >> n >> A >> B >> k;

    init();

    long long rs = 0;
    for (long long a = 0; a <= n; a++){
        if (a*A > k)
            break;
        if ((k - a*A) % B != 0)
            continue;
        long long b = (k - a*A) / B;
        rs = (rs + combi(n, a) * combi(n, b) % P) % P;
    }

    cout << rs << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
 
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define F first
#define S second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
#define ld long double 
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pii > vpii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef map<int,int> mii;
typedef unordered_map<int,int> umii;
typedef map<char,int> mci;
 
#define itv for(auto it= v.begin(); it != v.end(); ++it )
 
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
 
 
#define bs binary_search
#define  lb(v,val)  lower_bound(ALL(v), val); 
 
#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl "\n";
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18 
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define vin(v,n)   vi v(n); rep(i,0,n)  cin>>v[i];
//#define siz  (int)1e8
#define N 300000



void quickly_quickly_kro()
{
   int n,k; cin>>n>>k;

   vi h(n+1);

   rep(i,1,n+1)
   cin>>h[i];

   int dp[n+1];

   dp[1]=0;



   rep(i,2,n+1)
   { 

     dp[i]=INF;

    rep(j,1,k+1)
    {
 
     if(i-j>0)  
    dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));

    }




   }

   cout<<dp[n];

  




 
}
 
 
 
 
signed main()
{
 
 
 
   FAST
   
   int t; 
      t=1;              
  // cin>>t;
    while(t--)
    {
    
      quickly_quickly_kro();
      cout<<nl;
          
}
 
 
 

 
 
   return 0;
}

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

int main() {
  long long int x=100,z,count=0;
  cin>>z;
  //co=x;
  int i=1;
while(i)
  {
    
   // t=int(x/100);
  	
    x+=x/100;
  count++;
    //cout<<x;
    if(x>=z)
    i=0;
  }
  cout<<count;
}


Measured memory_bytes: 3636
#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, m;
  cin >> n >> m;
  if (n == m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	string S;
  	cin >> S;
    vector<string> words = {"dream", "dreamer", "erase", "eraser"};
	int N = words.size();
	int ssz = S.size();
    bool flag = false;
    
    while(1){
    	flag = false;
    	rep(i,N){
        	int wsz = words[i].size();
			if(ssz - wsz >= 0 && S.substr(ssz-wsz) == words[i]){
				flag = true;
                S = S.erase(ssz-wsz);
                break;
            }
        }
	    if(!flag){
			//NG
            puts("NO");
            return;
        }
        ssz = S.size();
        if(ssz == 0){
			break;
        }
    }

	puts("YES");
	return;
}

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



Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n;
    cin >> n;
    
    li ans = 0;
    for (int divisor = 1; divisor <= n; ++divisor) {
        li x = n / divisor;
        ans += x * (x + 1) / 2 * divisor;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;


int main() {
  int n; cin >> n;
  int x = n / 100;
  int y = (n - x*100) / 10;
  int z = n % 10;
  if (x == 7|| y == 7|| z == 7 ) cout << "Yes";
  else cout << "No";
  cout << endl;
  return 0;
  
}

Measured memory_bytes: 3620
#template
def inputlist(): return [int(j) for j in input().split()]
#template
def divisore(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors
N = int(input())
ans = 0
for i in range(1,N+1):
    if i % 2 == 0:
        continue
    li = divisore(i)
    if len(li) == 8:
        ans +=1
print(ans)

Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;

int main()
{
  int N; cin >> N;
  vector<int> W(N);
  int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> W[i];
    sum += W[i];
  }

  int ret = inf;
  int psum = 0;
  for(int i = 0; i < N; i++){
    psum += W[i];
    ret = min(ret, abs(psum - (sum - psum)));
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
const int MAX_V = 1e5;
vector<int> g[MAX_V], d(MAX_V,-1);

void dfs(int p, int l) {
  d[p] = l;
  for(auto k : g[p]) {
    if(d[k] == -1) dfs(k,l+1);
  }
}

int main(){
  int n, u, v, x, y;
  cin >> n >> u >> v;
  u--; v--;
  rep(i,n-1) {
    cin >> x >> y;
    x--; y--;
    g[x].push_back(y); g[y].push_back(x);
  }
  if(g[u].size() == 1 && g[u][0] == v) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> du(n), dv(n);
  dfs(u,0); 
  rep(i,n) du[i] = d[i];
  rep(i,n) d[i] = -1;
  dfs(v,0);
  rep(i,n) dv[i] = d[i];
  int ans = 1;
  rep(i,n) {
    if(du[i] < dv[i]) ans = max(ans,dv[i]-1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9472
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, X := sc.nextInt(), sc.nextInt()
	diff := make([]int, N)
	for i := 0; i < N; i++ {
		x := sc.nextInt()
		diff[i] = abs(X - x)
	}
	ans := diff[0]
	for i := 1; i < N; i++ {
		ans = gcd(ans, diff[i])
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,M;
    cin >> N >> M ;
    
    int a,b;
    
    vector<int> count(N,0);
    
    for(int i =0; i<M; i++){
    	cin >> a >> b;
        count.at(a-1) ++;
        count.at(b-1) ++;
    }
    
    for(int i=0; i<N; i++){
    	cout << count.at(i) << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    static int c;
    static ArrayList<ArrayList<Integer>> l;
    static int[] ps;
    static int N;
    static int M;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        l = new ArrayList<>();
        for(int i = 0; i<M; i++){
            ArrayList<Integer> ll = new ArrayList<>();
            int k = sc.nextInt();
            for(int j = 0; j<k; j++)ll.add(sc.nextInt()-1);
            l.add(ll);
        }
        ps = new int[M];
        for(int i = 0; i<M; i++) ps[i] = sc.nextInt();
        sc.close();
        int[] switches = new int[N];
        dfs(0,switches);
        System.out.println(c);
    }
    static void dfs(int i, int[] s){
        if(i==N){
            if(func(s)) c++;
            return;
        }
        dfs(++i,s);
        s[--i] = 1;
        dfs(++i,s);
        s[--i] = 0;
    }
    static boolean func(int[] s){
        int acs = 0;
        for(int i = 0; i<M; i++){
            ArrayList<Integer> ll = l.get(i);
            int cnt = 0;
            for(int j = 0; j<ll.size(); j++){
                if(s[ll.get(j)]==1) cnt++;
            }
            if(cnt%2 == ps[i]) acs++;
        }
        if(acs == M) return true;
        return false;
    }
}

Measured memory_bytes: 22228
#include <stdio.h>

int main()
{
    unsigned int a, b, c, d;

    if ( scanf("%u %u %u %u", &a, &b, &c, &d) != 4) {
        printf("Error!\n");
        return -1;
    }

    unsigned int area_ab = a * b, area_cd = c * d;

    if (area_ab > area_cd) printf("%u", area_ab);
    else                   printf("%u", area_cd);

    return 0;
}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int A, B, T; cin >> A >> B >> T;
    
    cout << (T/A)*B << endl;
    
    return 0;
}

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

string S; int a[500009], b[500009], c, ss, sum;

int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) a[i] = (S[S.size() - 1 - i] - '0');
	for (int i = 0; i < S.size(); i++) b[i] = a[i] * 9;
	for (int i = 0; i < S.size(); i++) {
		b[i + 1] += b[i] / 10;
		b[i] %= 10;
	}
	c = b[0];
	for (int i = 0; i <= S.size(); i++) b[i] = b[i + 1];
	for (int i = 0; i <= S.size(); i++) ss += b[i]; ss += c;
	for (int i = S.size(); i >= 0; i--) {
		if (ss == (i + 2) * 9) {
			break;
		}
		c += b[i]; sum += b[i];
		ss += (c / 10); ss -= c - (c % 10); b[0] += c / 10; c %= 10;
		for (int j = 0; j <= S.size(); j++) {
			if (b[j] <= 9) break;
			b[j + 1] += b[j] / 10; ss += b[j] / 10;
			ss -= 10 * (b[j] / 10); b[j] %= 10;
		}
	}
	sum++;
	cout << (sum + 8) / 9 << endl;
	return 0;
}

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

using namespace std;

void Main()
{
	string s;
	cin >> s;
	int count = 0;
	int left = 0;
	int right = s.length() - 1;
	while (left < right)
	{
		if (s[left] != s[right])
		{
			count++;
		}
		left++;
		right--;
	}
	cout << count << endl;
}

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

Measured memory_bytes: 256
#include<stdio.h>
#include <string.h>

int main()
{
	char card[2];
	int i, j, taro, mark, number, str[4][13] = { 0 };
	scanf("%d", &taro);
	for (i = 0; i<taro ; i++){
		scanf("%s %d", card, &number);
		if (strcmp(card,  "S") == 0){ mark = 0; }
		else if (strcmp(card, "H") == 0){ mark = 1; }
		else if (strcmp(card, "C") == 0){ mark = 2; }
		else if (strcmp(card, "D") == 0){ mark = 3; }
		str[mark][number - 1] = 1;
	}

	for (i = 0; i<4; i++){
		for (j = 0; j<13; j++){
			if (str[i][j] == 0){
				if (i == 0){ mark = 'S'; }
				else if (i == 1){ mark = 'H'; }
				else if (i == 2){ mark = 'C'; }
				else if (i == 3){ mark = 'D'; }
				printf("%c %d\n", mark, j + 1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define ll long long

int d = 365;
int k = 0;
vector<vector<int>> s(d, vector<int>(26, 0));
vector<ll> c(26);

void init() {
    cin >> d;
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    return;
}

ll calc(vector<int> out) {
    ll score = 0;
    k++;
    vector<ll> last(26, 0);
    for(int i = 0; i < out.size(); i++) {
        last[out[i]] = i+1; // タイプ番号
        //cout << "out[" << i << "] " << out[i] << " ";
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i+1)-last[j]);
        }
        score += s[i][out[i]];
        //cout << "score : " << score << endl;
    }

    int p = min(int(out.size()+k), int(d));
    //cout << p << endl;
    //if(out.size() >= d) return score;
    //cout << k << endl;
    for(int i = out.size(); i < p; i++) {
        for(int j = 0; j < 26; j++) {
            score -= c[j]*((i+1)-last[j]);
        }
    }
    return score;
}


int main() {
    init();
    vector<int> out;
    ll ans = 0;
    //ll tmp = 0;
    ll max_v = -1;
    //for(int k = 0; k < 26; k++) {
        //cout << "k: " << k << endl;
        //vector<int> out;
        for(int i = 0; i < d; i++) {
            //max_v = -100000000000;
            max_v = LLONG_MIN;
            int best = 0;
            for(int j = 0; j < 26; j++) {
                out.push_back(j);
                ll tmp = calc(out);
                if(max_v < tmp) {
                    max_v = tmp;
                    best = j;
                }
                out.pop_back();
            }
            out.push_back(best);
        }
    //}
    for(int i = 0; i < d; i++) {
        cout << out[i]+1 << endl;
    }
    //cout << max_v << endl;
    return 0;
}

Measured memory_bytes: 3684
package main

import "fmt"

func main() {
	var a,b,c string
	fmt.Scan(&a, &b, &c)
	if a[len(a)-1] == b[0] && b[len(b)-1] == c[0] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    int e;
    while(cin>>e,e){
        int ans=100000000;
        for(int z=0;z*z*z<=e;z++){
            for(int y=0;y*y<=e-z*z*z;y++){
                ans=min(ans,z+y+(e-(z*z*z+y*y)));
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 3008
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            long A = in.nextLong();
            long B = in.nextLong();
            System.out.println(A * B / gcd(A, B));
        }
    }

    public static final long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
}

Measured memory_bytes: 27032
#include <iostream>
#include <string>
#include <bits/stdc++.h>

using namespace std;


// adjacency matrix
// O(V^2) storage

// adjacency list
// O(V+E) storage

// dfs O(V+E) time
// bfs O(V+E) time


template <typename T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}

vector<int> dp(100000,-1);

int dfs(const vector<vector<int>>& G, int v) {
    // get longest path from node v

    if(dp[v]!=-1) {
        return dp[v];
    }

    int res=0;
    for (auto &&u : G[v])
    {
        chmax(res, 1+dfs(G,u));
    }
    return dp[v]=res;
}

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

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


    vector<vector<int>> G;
    G.resize(N);
    int x,y;
    for (size_t i = 0; i < M; ++i)
    {  
        cin>>x>>y;
        G[x-1].push_back(y-1);
    }

    int res;
    for (size_t i = 0; i < N; ++i)
    {
        chmax(res, dfs(G,i));
    }
    
    cout << res<<"\n";
}

Measured memory_bytes: 8192
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.next()
  var ans = ""
  for (c <- s) {
    c match {
      case '0' => ans += "0"
      case '1' => ans += "1"
      case 'B' => ans = ans.init
    }
  }
  println(ans)
}


Measured memory_bytes: 55240
// Problem : 
// 			A - Circle
// 			Editorial
// 		
// Contest : AtCoder - AtCoder Beginner Contest 145
// URL : https://atcoder.jp/contests/abc145/tasks/abc145_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int t;
	cin>>t;
	cout<<t*t<<nl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3588
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int[][] map = new int[14][14];
		int count = 0,max = 0;
		
		while(sc.hasNext()){
			
			int[] x = new int[3];
			
			String[] code = sc.next().split(",",0);
			
			for(int i = 0; i < code.length; i++)
				x[i] = Integer.parseInt(code[i]);
			
			x[0] += 2;
			x[1] += 2;
			
			if(x[2] >= 1){
				map[x[0]][x[1]]++;
				map[x[0]][x[1]-1]++;
				map[x[0]][x[1]+1]++;
				map[x[0]-1][x[1]]++;
				map[x[0]+1][x[1]]++;
				}
			if(x[2] >= 2){
				map[x[0]-1][x[1]-1]++;
				map[x[0]+1][x[1]-1]++;
				map[x[0]-1][x[1]+1]++;
				map[x[0]+1][x[1]+1]++;
			}
			if(x[2] == 3){
				map[x[0]][x[1]-2]++;
				map[x[0]][x[1]+2]++;
				map[x[0]+2][x[1]]++;
				map[x[0]-2][x[1]]++;
			}
		}
		for(int i = 2; i < 12; i++){
			for(int j = 2; j < 12; j++){
				if(map[i][j] > 0)count++;
				if(max < map[i][j])max = map[i][j];
			}
		}
		System.out.println(100 - count);
		System.out.println(max);
		
		sc.close();
	}
}

Measured memory_bytes: 17164
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = d-b, y = c-a;
    printf("%d %d %d %d\n", c-x, d+y, a-x, b+y);
    return 0;
}

Measured memory_bytes: 3760
#include<stdio.h>
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main( void )
{
    int A, B, C, D, E, k;
	cin >> A >> B >> C >> D >> E >> k;

    if(E - A > k){
        cout << ":(" << "\n";
    }else{
        cout << "Yay!" << "\n";
    }

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i,n) for(int i=0;i<(n);i++)
#define MARK 'X'
using namespace std;
 
int H, W;
char map[100][100], f;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
 
void dfs(int x, int y)
{
  map[x][y] = MARK;
  REP(i,4){
    int next_x = x+dx[i], next_y = y+dy[i];
    if(next_x < 0 || next_x >= H || next_y < 0 || next_y >= W || map[next_x][next_y] != f) continue;
    dfs(next_x,next_y);
  }
}
 
int main()
{
  while(1){
    cin >> H >> W;
    if(H == 0 && W == 0) break;
    int ans = 0;
    REP(i,H) REP(j,W) cin >> map[i][j];
    REP(i,H){
      REP(j,W){
        if(map[i][j] != MARK){
          f = map[i][j];
          dfs(i,j);
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3492
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
using namespace std;
using ll = long long;
using ld = long double;

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

	int n; cin>>n;
	string line; cin>>line;
	vector<int> cntr(n, 0), cntw(n, 0); if(line[0]=='R') cntr[0]++; else cntw[0]++;
	for(int i=1; i<n; i++) {
		cntr[i] = cntr[i-1]+(line[i]=='R');
		cntw[i] = cntw[i-1]+(line[i]=='W');
	}
	int ans = cntr[n-1];
	for(int i=0; i<n; i++) {
		int tmp = max(cntw[i], cntr[n-1]-cntr[i]);
		//cout << "tmp = "<< tmp << '\n';
		ans = min(ans, tmp);
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 4648
A,B,C = map(int,input().split())

def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b,a%b)
  
A,B = (A,B) if A>B else (B,A)
g = gcd(A,B)

if C%g==0:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 9036
#include<stdio.h>
int main()
{
	int n,m,a[100];
	int i,c=0;
	double x=0;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		x+=a[i];
	}
	x=x/(4*m);
	for(i=0;i<n;i++){
		if(x<=a[i]){
			c++;
		}
	}
	if(m<=c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int mod = (int)1e9+7;
        // out.println("AMAN");
        int n = sc.nextInt(), m = sc.nextInt();
        String[] s = new String[n];
        for(int i=0;i<n;i++) {
            s[i] = sc.next();
        }
        int dp[][] = new int[n+1][m+1];
        dp[1][1] = 1;
        for(int i=1;i<n+1;i++) {
            for(int j=1;j<m+1;j++) {
                if(j==1 && i==1) continue;
                if(s[i-1].charAt(j-1)=='#') dp[i][j]=0;
                else dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
            }
        }
        out.print(dp[n][m]);

        out.flush();
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

Measured memory_bytes: 30776
#include <bits/stdc++.h>
using namespace std;
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)

int n, m;
const int MAXN = 2010;
const int MAXM = 2010;
const int INF = 1000000007;

/* library */

// http://h0rnet.hatenablog.com/entry/2016/03/12/JOI_10_%E6%9C%AC%E9%81%B8_Planetary_Exploration_%28_%E4%BA%8C%E6%AC%A1%E5%85%83BIT_%29
struct BIT {
    long long dat[MAXN][MAXM];
    void update(int x, int y, long long v) {
        v %= INF;
        for (int i = x; i <= n; i += i & -i) {
            for (int j = y; j <= m; j += j & -j) {
                dat[i][j] += v;
                if (dat[i][j] > INF) {
                    dat[i][j] %= INF;
                }
            }
        }
    }
    long long qsum(int x, int y) {
        long long res = 0;
        for (int i = x; i > 0; i -= i & -i) {
            for (int j = y; j > 0; j -= j & -j) {
                res += dat[i][j];
            }
            res %= INF;
        }
        return res;
    }
    int qsum(int x0, int y0, int x1, int y1) {
        return qsum(x1, y1) - qsum(x0 - 1, y1) - qsum(x1, y0 - 1) + qsum(x0 - 1, y0 - 1);
    }
};

/* main */

signed main() {
    int N, M;
    cin >> N >> M;
    n = N + 1;
    m = M + 1;
    vector<long long> S(N + 1, -1), T(M + 1, -1);
    FOR(i, 0, N) {
        cin >> S[i + 1];
    }
    FOR(i, 0, M) {
        cin >> T[i + 1];
    }
    BIT DP;
    DP.update(1, 1, 1);
    FOR(i, 1, N + 1) {
        FOR(j, 1, M + 1) {
            if (S[i] == T[j]) {
                long long tmp = DP.qsum(i, j);
                DP.update(i + 1, j + 1, tmp);
            }
        }
    }
    cout << DP.qsum(N + 1, M + 1) << endl;
}


Measured memory_bytes: 31872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  int L=A+B;
  int R=C+D;
  
  if (L>R) {
    cout<<"Left"<<endl;
  }
  else if (L==R) {
    cout<<"Balanced"<<endl;
  }
  else if (L<R) {
    cout<<"Right"<<endl;
  }
  }

Measured memory_bytes: 3572
#include<iostream>
#include<functional>
#include<queue>
#include<deque>
#include<vector>
#include<algorithm>
using namespace std;

inline void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (true) {
		k = getchar_unlocked();
		if (k < '0') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
inline void writeln(int x) {
	int s = 0, p; char f[7];
	while (x) {
		p = x; x /= 10;
		f[s++] = p - (x << 1) - (x << 3);
	}
	if (!s) f[s++] = 0;
	while (s--) putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}
#pragma warning(disable:4996)
int n, m, q, a[200003], b[200003], c[200003], d[200003], e[100003], f[100003], g[100003];
int h1[100003], h2[100003], h3[100003], h4[100003], dist[100003], E[200003];
vector<pair<int, int> > z[100003]; vector<int> x[100003];
vector<int>D[100003];
int Q1[110000], Q1L, Q1R;
int main() {
	reader(&n); reader(&m); reader(&q);
	fill(d, d + m + 1, 1 << 30);
	for (int i = 1; i <= m; i++) { reader(&a[i]), reader(&b[i]); f[a[i]]++; f[b[i]]++; }
	for (int i = 1; i <= q; i++) reader(&c[i]), d[c[i]] = i;
	for (int i = 1; i <= n; i++) { x[i].resize(f[i]); }
	for (int i = 1; i <= m; i++) {
		x[a[i]][g[a[i]]] = b[i]; g[a[i]]++;
		x[b[i]][g[b[i]]] = a[i]; g[b[i]]++;
	}
	fill(dist, dist + n + 1, -1); dist[1] = 0;
	Q1[0] = 1; Q1R = 1;
	while (Q1R > Q1L) {
		int a1 = Q1[Q1L]; Q1L++;
		for (int i : x[a1]) {
			if (dist[i] == -1) {
				dist[i] = dist[a1] + 1;
				Q1[Q1R] = i; Q1R++;
			}
		}
	}
	int rn = 0;
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]]) h1[a[i]]++;
		if (dist[b[i]] > dist[a[i]]) h1[b[i]]++;
	}
	for (int i = 1; i <= n; i++)z[i].resize(h1[i]);
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]]) { z[a[i]][h2[a[i]]] = make_pair(b[i], d[i]); h2[a[i]]++; }
		if (dist[b[i]] > dist[a[i]]) { z[b[i]][h2[b[i]]] = make_pair(a[i], d[i]); h2[b[i]]++; }
	}
	for (int i = 1; i <= n; i++) { h3[dist[i]]++; rn = max(rn, dist[i]); }
	for (int i = 0; i <= rn; i++) D[i].resize(h3[i]);
	for (int i = 1; i <= n; i++) D[dist[i]][h4[dist[i]]] = i, h4[dist[i]]++;
	e[1] = (1 << 30);
	for (int i = 1; i <= rn; i++) {
		for (int j : D[i]) {
			for (pair<int, int>k : z[j]) {
				e[j] = max(e[j], min(e[k.first], k.second));
			}
		}
	}
	for (int i = 2; i <= n; i++) {
		if (e[i] < 300000) E[e[i]]++;
	}
	for (int i = 1; i <= q; i++) {
		E[i] += E[i - 1];
		writeln(E[i]);
	}
	return 0;
}

Measured memory_bytes: 25032
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	
	private static class Element {
		public int value;
		public int cnt;
		
		public Element(int value , int cnt) {
			this.value = value;
			this.cnt = cnt;
		}
		
		public String toString() {
			return String.format("(%d , %d)" , this.value , this.cnt);
		}
		
	}
	
	private static int[] input = new int[100010];
	
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		List<Element> list = new ArrayList<Element>();
		int i , j , n = scan.nextInt() , ans = 0;
		for (i = 0;i < n;i ++)
			input[i] = scan.nextInt();
		Arrays.sort(input , 0 , n);
		for (i = 0;i < n;i ++) {
			int value = input[i];
			int cnt = 0;
			while (i < n && (input[i] == value)) {
				i ++;
				cnt ++;
			}
			i --;
			list.add(new Element(value , cnt));
		}
		
		i = 0;
		j = list.size() - 1;
		while (i < j) {
			
			if (list.get(i).cnt < list.get(j).cnt) {
				int next = list.get(j).cnt - (list.get(i).cnt - 1);
				list.get(j).cnt = next;
				list.get(i).cnt = 1;
				i ++;
				ans ++;
			} else if (list.get(i).cnt > list.get(j).cnt) {
				int next = list.get(i).cnt - (list.get(j).cnt - 1);
				list.get(i).cnt = next;
				list.get(j).cnt = 1;
				j --;
				ans ++;
			} else {
				ans += 2;
				i ++;
				j --;
			}
			
		}
		
		if (list.get(i).cnt % 2 == 1) 
			ans ++;
		
		System.out.println(ans);
		
	}
	
}




	

Measured memory_bytes: 32212
n=int(input())
word_list=[]
last_word='aaaa'
for i in range(n):
    w=input()
    if 0<i and (w in word_list or last_word[len(last_word)-1]!=w[0:1]):
        print('No')
        exit()
    word_list.append(w)
    last_word=w
print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int mx[100010],mn[100010],head[100010],o=0,k,n,t,a[100010],up_mx[100010],up_mn[100010];
bool sure[100010];
struct edge{
	int to,link;
}e[200010];
void add_edge(int u,int v){
	e[++o].to=v,e[o].link=head[u],head[u]=o;
	e[++o].to=u,e[o].link=head[v],head[v]=o;
}
void dfs(int u,int pre,int down_mx,int down_mn){
	if(sure[u]) down_mx=mx[u],down_mn=mn[u],up_mx[u]=mx[u]+1,up_mn[u]=mn[u]-1;
	else mx[u]=down_mx,mn[u]=down_mn;
	for(int i=head[u];i;i=e[i].link){
		if(e[i].to==pre) continue;
		dfs(e[i].to,u,down_mx+1,down_mn-1);
		mx[u]=min(mx[u],up_mx[e[i].to]),mn[u]=max(mn[u],up_mn[e[i].to]);
	}
	up_mx[u]=mx[u]+1,up_mn[u]=mn[u]-1; 
}
void work(int u,int pre,int now){
	a[u]=now;
	for(int i=head[u];i;i=e[i].link){
		if(e[i].to==pre) continue;
		if(now-1>=mn[e[i].to]) work(e[i].to,u,now-1);
		else work(e[i].to,u,now+1);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++) scanf("%d %d",&u,&v),add_edge(u,v);
	scanf("%d",&k);
	for(int i=1,v,p;i<=k;i++) scanf("%d %d",&v,&p),mx[v]=mn[v]=p,t=v,sure[v]=true;
	dfs(t,0,1e6,-1e6);
	for(int i=1;i<=n;i++) if(mx[i]<mn[i]){
		printf("No\n");
		return 0;
	}
	work(t,0,mx[t]);
	for(int i=1;i<=n;i++) if(a[i]>mx[i]){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for(int i=1;i<=n;i++) printf("%d\n",a[i]);
} 

Measured memory_bytes: 11136
#include <stdio.h>
int main(void){

 int a,b,c;
 int n,i;
 int s;
 scanf("%d%d%d",&a,&b,&c);
 s=0;
 for(i=a;i<=b;i++){
 if(c%i==0){
 s++;

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

}

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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}
  
int h,w;

int search(vector<string> m, int sx, int sy)
{
  queue<tuple<int, int, int>> next;

  next.push(make_tuple(sx, sy, 0));

  int res = 0;
  while (!next.empty()) {
    int x = get<0>(next.front());
    int y = get<1>(next.front());
    int d = get<2>(next.front());
    next.pop();

    if (x < 0 || x >= w || y < 0 || y >= h) {
      continue;
    }

    if (m[y][x] == '.') {
      m[y][x] = '#';
      next.push(make_tuple(x + 1, y, d + 1));
      next.push(make_tuple(x - 1, y, d + 1));
      next.push(make_tuple(x, y + 1, d + 1));
      next.push(make_tuple(x, y - 1, d + 1));
      res = max(res, d);
    } else {
      continue;
    }
  }

  return res;
}

int main() {
  init();

  cin >> h >> w;

  vector<string> m(h);
  for (int i = 0; i < h; i++)
  {
    string s;
    cin >> s;
    m[i] = s;
  }
  
  int mx = 0;
  for (int y = 0; y < h; y++)
  {
    for (int x = 0; x < h; x++)
    {
      mx = max(search(m, x, y), mx);
    }
  }

  cout << mx << '\n';

  return 0;
}


Measured memory_bytes: 256
main :: IO ()
main = do ls <- getContents
          putStrLn (compose ls)

compose :: String -> String
compose = unwords . fmap show . mathOp . takeElems . (=<<) toWordsInt . lines
           where
             takeElems xs = take (head xs) (tail xs)
             toWordsInt =  fmap (\x -> read x::Int) . words

mathOp  :: [Int] -> [Int]
mathOp  xs = fmap ($ xs) [mini, maxi, sumi]

mini :: [Int] -> Int
mini [] = error "Empty list was given"
mini [x] = x
mini (x:y:xs) | x <= y = mini (x:xs)
              | otherwise = mini (y:xs)

maxi :: [Int] -> Int
maxi [] = error "Empty list was given"
maxi [x] = x
maxi (x:y:xs) | x < y = maxi (y:xs)
              | otherwise = maxi (x:xs)

sumi :: [Int] -> Int
sumi = foldr (+) 0

Measured memory_bytes: 5476
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int MAXN = 1e5+7;
int n,tp;
pii sta[MAXN];
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> sta[i].first;
        sta[i].second = i;
    }
    sort(sta+1,sta+1+n,[&](const pii A,const pii B)->bool{return A.first < B.first;});
    for(int i = 1; i <= n; i++) cout << sta[i].second << ' ';
    return 0;
}

Measured memory_bytes: 1536
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
class Combination {
    int powmod(int a, int p) {
        int ans = 1;
        int mul = a;

        for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }

        return ans;
    }
public:
    int N;
    int mod;
    vector<int> fact;
    vector<int> revFact;

    Combination(int n, int m) : N(n), mod(m), fact(n+1), revFact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= N; i++) {
            fact[i] = fact[i-1] * i;
            fact[i] %= mod;
        }

        // Fermat's little theorem
        revFact[N] = powmod(fact[N], mod - 2);

        for (int i = N-1; i >= 0; i--) {
            revFact[i] = revFact[i+1] * (i+1);
            revFact[i] %= mod;
        }
    }

    int get(int a, int b) {
        if (a < 0 || b < 0) return 0;
        if (b > a) return 0;
        return (((fact[a] * revFact[b]) % mod) * revFact[a-b]) % mod;
    }
};

signed main() {
    int N, M, K;
    cin >> N >> M >> K;

    Combination comb = Combination(N * M, MOD);

    int ret = 0;
    for (int d = 1; d <= M - 1; d++) {
        ret += ((((((M - d) * N) % MOD) * N) % MOD) * d) % MOD;
        ret %= MOD;
    }
    for (int d = 1; d <= N - 1; d++) {
        ret += ((((((N - d) * M) % MOD) * M) % MOD) * d) % MOD;
        ret %= MOD;
    }
    ret *= comb.get(N * M - 2, K - 2);
    ret %= MOD;

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod = 10e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prtd(n, var)  cout << fixed << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl
#define prt3(var1, var2, var3) cout << var1 << " " << var2 << " " << var3 << endl

//----------------------------------------------------------------
string digit(int n, int k){
  string s;
  if(k==0){s="0";}
  while(k>0){
    if(k%2==0){
      s.push_back('0');
    } else {
      s.push_back('1');
      k -= 1;
    }
    k/=2;
  }

  while(s.size()<n){
    s.push_back('0');
  }
  return s;
}

int main(void) {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> sw;
  rep(i,m){
    int k;
    cin >> k;
    vector<int> s(k);
    sw.push_back(s);
    rep(j,k){
      int tmp;
      cin >> tmp;
      sw[i][j]=tmp-1;
    }
  }
  vec cond(m);
  rep(i,m){
    cin >> cond[i];
  }

  ll ans=0;
  rep(i,pow(2,n)){
    int light=0;
    string pattern = digit(n, i);

    rep(k,m){
      int on = 0;
      rep(j,sw[k].size()){
        if(pattern[sw[k][j]]=='1'){on++;}
      }
      if(on%2==cond[k]){
        light++;
      }
    }
    if(light==m){
      ans++;
    }
  }

  prt(ans);
}


Measured memory_bytes: 640
N=int(input())
def factors(x):
   t=[]
   for i in range(2, int(x**0.5)+1):
       if x % i == 0:
           t.append(i)
           if x//i!=i:
               t.append(x//i)     
   return t
ans=2+len(factors(N-1))
fac=factors(N)
for i in fac:
    n=N
    while n%i==0:
        n=n//i
    n=n%i
    if n==1:
        ans+=1
if N==2:
    print(1)
else:  
    print(ans)
        
        



Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main()
{
    int n,a,b,c,d,q=0;
    cin>>n;
    a=n/10;
    b=n%10;
    c=a%10;
    d=a/10;
    if(b==1){q++;}
    if(c==1){q++;}
    if(d==1){q++;}
    cout<<q;
   return 0;
}


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

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

ll lcm(ll a, ll b) {
    return (a * (b / gcd(a, b)));
}

int main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    ll L = lcm(n, m);
    set<ll> a;
    for(int i = 0; i < n; i++) {
        a.insert(i * (L / n));
    }
    bool ok = true;
    for(int i = 0; i < m; i++) {
        ll x = i * (L / m);
        if(a.count(x) && t[i] != s[x / (L / n)]) {
            ok = false;
        }
    }
    if(ok) {
        cout << L << '\n';
    }
    else {
        cout << -1 << '\n';
    }
    return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
double xs[10], ys[10];
int perm[10];

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

  std::cin >> N;

  for(int i=0;i<N;++i){
      std::cin >> xs[i] >> ys[i];
  }

  std::iota(perm, perm + N, 0);

  double s = 0;
  int c = 0;

  while(true){
      for(int i=1;i<N;++i){
          double dx = xs[perm[i]] - xs[perm[i-1]],
              dy = ys[perm[i]] - ys[perm[i-1]],
              d = std::sqrt(dx * dx + dy * dy);

          s += d;
      }

      c += 1;

      unless(std::next_permutation(perm, perm + N)){
          break;
      }
  }

  double average = s / c;
  printf("%.10f\n", average);
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        mut s: [Chars;n],
        m: usize,
        mut t: [Chars;m],
    }

    s.sort();
    s.push(['d'].to_vec());
    t.sort();
    t.push(['d'].to_vec());
    // debug!(s);
    // debug!(t);
    let mut cnt = 1;
    let mut ret_s: Vec<(String, usize)> = Vec::new();
    let mut ret_t: Vec<(String, usize)> = Vec::new();
    if n==1 {
        ret_s.push((s[0].iter().collect(), 1));
    } else {
        for i in 1..n+1 {
            let s1_tmp: String = s[i].iter().collect();
            let s0_tmp: String = s[i-1].iter().collect();
            if s0_tmp==s1_tmp {
                cnt += 1;
            } else {
                ret_s.push((s0_tmp, cnt));
                cnt = 1;
            }
        }
    }

    cnt = 1;
    if m==1 {
        ret_t.push((t[0].iter().collect(), 1));
    } else {
        for i in 1..m+1 {
            let t1_tmp: String = t[i].iter().collect();
            let t0_tmp: String = t[i-1].iter().collect();
            if t0_tmp==t1_tmp {
                cnt += 1;
            } else {
                ret_t.push((t0_tmp, cnt));
                cnt = 1;
            }
        }
    }
    debug!(ret_s.len());
    debug!(ret_t.len());
    let mut ans: Vec<i64> = Vec::new();
    let mut ok = false;
    for i in 0..ret_s.len() {
        for j in 0..ret_t.len() {
            if ret_s[i].0==ret_t[j].0 {
                ans.push(max(0, (ret_s[i].1 as i64)-(ret_t[j].1 as i64)));
                ok = true;
            }
        }
        if ok==false {
            ans.push(ret_s[i].1 as i64);
        } else {
            ok = false;
        }
        
    }
    ans.sort();
    ans.reverse();
    println!("{}", ans[0]);
}


Measured memory_bytes: 2164
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int n = sc.nextInt()*2;
		String s = sc.next();
			
		
		char f[] = new char[n/2];
		char b[] = new char[n/2];
		
		for(int i = 0; i < n/2;i++){
			f[i] = s.charAt(i);
			b[i] = s.charAt(n-i-1);
		}
		
		Map<String,Integer> fmap = new HashMap<String,Integer>();
		Map<String,Integer> bmap = new HashMap<String,Integer>();
		
		for(int i = 0 ; i < (1 << (n/2)); i++){
			
			StringBuilder left = new StringBuilder();
			StringBuilder right = new StringBuilder();
			
			StringBuilder bleft = new StringBuilder();
			StringBuilder bright = new StringBuilder();
			
			
			for(int j = 0 ; j < n/2 ; j++){
				if( (i & (1<<j)) != 0 ){
					left.append(f[j]);
					bleft.append(b[j]);
				}else{
					right.append(f[j]);
					bright.append(b[j]);
				}
			}
			
			fmap.put(left+":"+right, fmap.getOrDefault(left+":"+right,0)+1);
			bmap.put(bleft+":"+bright, bmap.getOrDefault(bleft+":"+bright, 0)+1);
						
		}
		
		long ans =0 ;
		for(String key : fmap.keySet()){
			ans += (long)fmap.getOrDefault(key,0) * (long)bmap.getOrDefault(key, 0);
		}
		System.out.println(ans);
	}
	
	
	boolean eqlike(char[] r,char[] b){
		for(int i = 0; i < r.length;i++){
			if(r[i] ==0 || b[i]==0){
				continue;	
			}
			if(r[i] != b[i]){
				return true;
			}
		}
		return true;
	}
	
	
}


Measured memory_bytes: 264820