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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int a[123];
int main()
{
	int n, m;
	cin >> n >> m;
	int s = 0;
	for(int i = 1; i <= n; i ++)
		cin >> a[i], s += a[i];
	sort(a + 1, a + n + 1);
	reverse (a + 1, a + n + 1);
	int q = 0, flag = 0;
	if(s % (4*m) == 0)
	{
		q = s / (4*m);
		flag = 1;
	}
	else
	{
		q = s / (4*m);
	}
	int ans = 0;
	for(int i = 1; i <= n; i ++)
	{
		if(flag)
		{
			if(a[i] >= q)
				ans ++;
		}
		else
			if(a[i] > q)
				ans ++;
	}
	if(ans >= m)
		cout << "Yes";
	else
		cout << "No";


	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 256
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
#define LM 55555
using namespace::std;


long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

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

int A,B,C,X,Y,N, M,num,v[55555],ch,ans;
string s, t[1000];
bool a, b, c;
int main() {
	cin >> N >> M;
	ans = 0;
	if (N*M >= N + M) {
		ans = M*N;
	}
	else {
		ans = N + M;
	}

	if (ans <= N - M) {
		ans = N - M;
	}

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




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

#include <numeric>

#include <map>

#include <deque>

#include <cassert>

#include <memory>

#include <numeric>

using namespace std;

typedef unsigned long long LL;

char s[4444];

int r[4444], g[4444], b[4444], n;

LL ans;

LL get_ans(char x, char y, int i, int j) {
    LL ret = 0;
    char z;
    map<char, int> m;
    m['R'] = 1;
    m['B'] = 1;
    m['G'] = 1;
    m[x] -= 1;
    m[y] -= 1;
    if (m['R'] == 1) z = 'R';
    if (m['G'] == 1) z = 'G';
    if (m['B'] == 1) z = 'B';
    if (z == 'R') {
        ret = r[n] - r[j];
    }
    if (z == 'G') {
        ret = g[n] - g[j];
    }
    if (z == 'B') {
        ret = b[n] - b[j];
    }
    if (j + j - i <= n) {
        char zz = s[j + j - i];
        //cout << zz << endl;
        if (zz != x && zz != y) ret -= 1;
    }

    //cout << x << ' ' << y << ' ' << i << ' ' << j << ' ' << ret << endl;

    return ret;

}

int main() {

    cin >> n;

    scanf("%s", s + 1);

    for (int i = 1; i <= n; ++i) {
        r[i] = r[i - 1];
        g[i] = g[i - 1];
        b[i] = b[i - 1];
        if (s[i] == 'R') r[i] += 1;
        if (s[i] == 'G') g[i] += 1;
        if (s[i] == 'B') b[i] += 1;
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            if (s[j] == s[i]) continue;
            ans += get_ans(s[i], s[j], i, j);
        }
    }

    cout << ans << endl;


}

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

namespace AtCoder.Contest.A
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			string s = cin.next();
			string t = cin.next();

			if (t.Substring(0, s.Length) == s) Console.WriteLine("Yes");
			else Console.WriteLine("No");

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

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

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

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

		public int nextInt()
		{
			return int.Parse(next());
		}

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

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

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

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

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

Measured memory_bytes: 25784
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    int N, D;
    cin >> N >> D;

    const int a = 2 * D +1;
    cout << ((N + a - 1) / a) << endl;
    
    return 0;
}


Measured memory_bytes: 256
<?php
  $k = trim(fgets(STDIN));

  $n = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
  $a = explode(",", $n);
  echo trim($a[$k-1]);

Measured memory_bytes: 4856
import sys
from itertools import product

import numpy as np

N, M, X = map(int, input().split(' '))
books = np.fromiter(sys.stdin.read().split(), dtype=int).reshape((N, M + 1))
indexes = np.arange(0, N, dtype=int)

min_cost = 10 ** 9
for bool_indexes in product((False, True), repeat=N):
    bool_indexes = list(bool_indexes)
    if np.min(np.sum(books[indexes[bool_indexes], 1:], axis=0)) >= X:
        min_cost = min(min_cost, books[indexes[bool_indexes], 0].sum())

if min_cost == 10 ** 9:
    min_cost = -1

print(min_cost)


Measured memory_bytes: 27328
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll A, B, K;
    cin >> A >> B >> K;
    vector<ll> v;
    set<ll> s;
    for(ll i = 0; i < K; i++){
        if(B < A + i) break;
        s.insert(A + i);
    }
    for(ll i = 0; i < K; i++){
        if(B - i < A) break;
        s.insert(B - i);
    }
    for(auto ite = s.begin(); ite != s.end(); ite++) v.push_back(*ite);
    sort(v.begin(), v.end());
    for(ll po : v) cout << po << endl;
    return 0;
}

Measured memory_bytes: 256
from math import factorial,sqrt
from itertools import permutations

def dfs(s):
    pass

n = int(input())
v = []
x = 0
for _ in range(n):
    v.append(tuple(map(int,input().split())))
for t in permutations(v):
    z = 0
    for i in range(n-1):
        ti = t[i]
        tn = t[i+1]
        z+=sqrt((abs(ti[0]-tn[0])**2)+(abs(ti[1]-tn[1])**2))
    x+=z
print(x/factorial(n))


Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main() {
	double N;
	double sum;
	vector<int> points;
	double sum_diff;

	while (true)
	{
		double ave;
		sum_diff = 0;
		sum = 0;
		N = 0;
		ave = 0;
		cin >> N;

		if (N == 0) break;

		// ????¨?????¨????
		for (size_t i = 0; i < N; i++)
		{
			int point;
			cin >> point;
			// ??????????????°???????????????
			points.push_back(point);
			sum += point;
		}

		// ??????
		ave = sum / N;

		// ????????¨??????????????\??????????????\??????
		for (size_t i = 0; i < points.size(); i++)
		{
			// ?????????????¨?????¨??????????
			sum_diff += pow((points[i] - ave), 2.0);
		}

		// ??????
		cout << std::fixed << std::setprecision(10)
			 << sqrt(sum_diff / N) << endl;
		points.clear();
	}
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	int n, k, ans = 0;
	cin >> n >> k;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	sort(p.begin(), p.end());
	rep(i,k) ans += p[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

#define _USE_MATH_DEFINENS
#include <cmath>

#define ip "%d"
#define op "%d\n"

using namespace std;

#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int k;
    scanf(ip, &k);
    printf(op, (k / 2) * ((k + 1) / 2));
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int n,h[225816],a[225816];
ll bit[225816];

void update(int i, ll v){
	while(i<=n){
		bit[i] = max(v,bit[i]);
		i += i&(-i);
	}
}

ll query(int i){
	ll v=0ll;
	while(i){
		v = max(v,bit[i]);
		i -= i&(-i);
	}
	return v;
}

int main(void){
	int i;
	ll ans=0ll,tmp;
	fill(bit,bit+225816,0ll);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> h[i];
	}
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	for(i=0; i<n; ++i){
		tmp = query(h[i]-1)+a[i];
		ans = max(ans,tmp);
		update(h[i],tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 200000;
const long long MOD = 1000000007;

int main(){
    int N;
    int A[MAX];
    long long sum = 0;

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

    long long ans = 0;

    for(int i = 0;i < N;i++){
        sum -= A[i];
        ans = (ans + A[i] * (sum % MOD)) % MOD;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
int main()
{
  int n ;
  cin >> n ;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];

  bool flag = 1 ;
  sort(a,a+n) ;
  for(int i=0;i<n;i++)
  {
      if(a[i]==a[i+1])
      {
        cout << "NO" << endl;
        flag = 0;
        break ;
      }
  }

  if(flag)
    cout << "YES" << endl;
  
    return 0;
}


Measured memory_bytes: 1024
package main

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

func main() {
	S := nextBytes()
	N := len(S)
	children := make([]int, N)
	lefts := make([]int, N)  // i番目とその左にいくつLが並んでいるか
	rights := make([]int, N) // i番目とその右にいくつRが並んでいるか

	for i := 0; i < N; i++ {
		if S[i] == 'L' {
			lefts[i] = lefts[i-1] + 1
		} else {
			lefts[i] = 0
		}
		j := N - 1 - i
		if S[j] == 'R' {
			rights[j] = rights[j+1] + 1
		} else {
			rights[j] = 0
		}
	}
	for i := 0; i < N; i++ {
		var p int
		if lefts[i] > 0 {
			// 初手左
			p = i - lefts[i]

			if lefts[i]%2 == 1 {
				p++
			}
		} else {
			// 初手右
			p = i + rights[i]

			if rights[i]%2 == 1 {
				p--
			}
		}
		children[p]++
	}

	for i := 0; i < N; i++ {
		fmt.Print(children[i])

		if i+1 == N {
			fmt.Printf("\n")
		} else {
			fmt.Printf(" ")
		}
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 6
#define eps 0.00001
#define REP(i,b,n) for(int i=(int)b;i<(int)n;i++)
#define rep(i,n)  REP(i,0,n)

double ans = -1;


void solve(int n,int now,bool *used,double *rc,double *lc,double lim,double c,int *weight){
  if ( n-1 == now){
    ans = max(ans,c);
    return;
  }
  
  //left i , right j
  rep(i,n){
    if ( used[i] == true)continue;
    rep(j,n){
      if (i == j)continue;
      if ( used[j] == true)continue;
      double w = weight[i]+weight[j];
      double tmpr=max(weight[i]/w+rc[j],-weight[j]/w+rc[i]);
      double tmpl=max(weight[j]/w+lc[i],-weight[i]/w+lc[j]);

      if ( tmpr+tmpl >lim+eps){continue;}
      double tr=rc[i],tl=lc[i];int tw=weight[i];
      used[j]=true;
      rc[i]=tmpr;
      lc[i]=tmpl;
      weight[i]=weight[i]+weight[j];
      solve(n,now+1,used,rc,lc,lim,tmpr+tmpl,weight);
      rc[i]=tr;
      lc[i]=tl;
      weight[i]=tw;
      used[j]=false;
    }
  }
  
}

main(){
 int te;
 cin>>te;
 while(te--){
   int n;
   double r;
   cin>>r>>n;
   int inp[n];
   rep(i,n)cin>>inp[i];

   double rc[n],lc[n];
   bool used[n];
   rep(i,n)rc[i]=lc[i]=0,used[i]=false;
   ans=-1;

   solve(n,0,used,rc,lc,r,0,inp);
   if ( ans == -1)puts("-1");
   else printf("%.9lf\n",ans);
 }
}

Measured memory_bytes: 984
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# 
# s = input()

u = "unsafe"
s = "safe"
S, W = list(map(int, input().split()))

if W >= S:
    print(u)
else:
    print(s)


Measured memory_bytes: 9176
import math 
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True # 全ての kで割り切れなかった場合
  
x = int(input())

while True:
  if is_prime(x):
    print(x)
    break
  x += 1


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#define ll long long 
using namespace std;

int main() {
	int m, n;
	int count = 0;
	string a[50], b[50];
	string ans = "No";
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	for (int i = 0; i <= n - m; i++) {
		for (int j = 0; j <= n - m;j++) {
			for (int k = 0; k < m; k++) {
				if (a[i + k].substr(j, m) == b[k]) {
					count++;
				}
				if (count == m) {
					ans = "Yes";
				}
				if (k == m - 1) {
					count = 0;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            String S = in.next();
            out.println(S.substring(0, 3));
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

    }
}



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

public class Main {
    char[] s1, s2;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    void read() {
        Scanner sc = new Scanner(System.in);
        s1 = sc.nextLine().toCharArray();
        s2 = sc.nextLine().toCharArray();
    }

    void solve() {
        int[][] dp = new int[s1.length+1][s2.length+1];
        for (int i = 0; i < s1.length + 1; i++) {
            Arrays.fill(dp[i], Integer.MAX_VALUE);
            dp[i][0] = i;
        }
        for (int j = 0; j < s2.length + 1; j++)
            dp[0][j] = j;

        for (int i = 1; i < dp.length; i++) {
            for (int j = 1; j < dp[0].length; j++) {
                int del, ins, match, rep;
                ins = dp[i-1][j] + 1;
                del = dp[i][j-1] + 1;
                rep = dp[i-1][j-1] + 1;
                if (s1[i-1] == s2[j-1])
                    match = dp[i-1][j-1];
                else
                    match = Integer.MAX_VALUE;
                int next = Math.min(Math.min(ins, del), Math.min(rep, match));
                dp[i][j] = Math.min(dp[i][j], next);
               // printArray(dp);
            }
            //printArray(dp);
        }
        System.out.println(dp[s1.length][s2.length]);
    }

    private void printArray(int[][] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                if (arr[i][j] == Integer.MAX_VALUE)
                    System.out.printf("INF ");
                else
                    System.out.printf("%3d ", arr[i][j]);
            }
            System.out.println();
        }
        System.out.println();
    }
}

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

int main(void){
	int N;
	int A,B;
	int C;
	vector<int> D;
	int ans = 100000000;
	
	scanf("%d", &N);
	scanf("%d %d", &A, &B);
	scanf("%d", &C);
	for(int i = 0; i < N; i++){
		int t;
		scanf("%d", &t);
		D.push_back(t);
	}
	
	sort(D.begin(), D.end());
	reverse(D.begin(), D.end());
	
	ans = C/A;
	
	for(int i = 0; i < N; i++){
		C+=D[i];
		if(ans < C/(A+(i+1)*B))ans = C/(A+(i+1)*B);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1232
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf = 10e17;
const ll mod = inf;//1000000007;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);


ll mulmod(ll x, ll y)
{
	return (x * y) % mod;
}

ll submod(ll x, ll y)
{
	return (x - y + 100 * mod) % mod;
}

ll power(ll n, ll r)
{
	if ( r == 0 ) { return 1; }
	if ( r == 1 ) { return n; }
	if ( n == 0 ) { return 0; }
	if ( n == 1 ) { return 1; }

	if (r % 2 == 0)
	{
		ll y = power(n, r/2);
		return mulmod(y, y);
	}
	else
	{
		ll y = power(n, (r-1)/2);
		return n * mulmod(y, y) % mod;
	}
}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

vector<ll> perm;
vector<ll> inv;
void init_inv(ll m)
{
	perm.resize(m);
	inv.resize(m);
	
	perm[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i < m; i++)
	{
		perm[i] = mulmod(perm[i-1], i);
	}
	
	for (ll i = 1; i < m; i++)
	{
		inv[i] = power(perm[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	// n (n-1) ... (n-r)
	if ( r == n || r == 0 ) { return 1; }

	ll ans = 1;
	for (ll i = 0; i < r; i++)
		ans = mulmod(ans, n - i);

	 return mulmod(ans, inv[r]);
	// return mulmod(perm[n], mulmod(inv[n-r], inv[r]));
}

bool binary_check(ll mid, ll key)
{
	return mid >= key;
}

ll binary_search()
{
//	ll ng = 0;
//	ll ok = x;
//
//	while (abs(ok - ng) > 1)
//	{
	//	ll mid = (ok+ng) / 2;
	//	if (binary_check(mid, k)) ok = mid;
	//	else ng = mid;
	//}

	return 0;
	//return ok;
}

void pushorcreate(map<ll, vector<ll>> &m, ll key, ll i)
{
	if (m.find(key) == m.end())
	{
		m[key] = vector<ll>(1, i);
	}
	else {
		m[key].push_back(i);
	}
}

ll solve(void)
{
	ll n;
	cin >> n;

	vector<ll> A(n);
	map<ll, vector<ll>> m; 
	map<ll, ll> c;

	for (ll i = 0; i < n; i++) {
		cin >> A[i];
		pushorcreate(m, A[i], i);
	}

	ll all = 0;
	for (auto mi : m)
	{
		ll i = mi.first;
		auto v = mi.second;
		auto s = v.size();
		c[i] = s * (s-1) / 2;
		all += c[i];
	}

	for (ll i = 0; i < n; i++)
	{
		ll key = A[i];
		ll size = m[key].size() - 1;
		ll ans = all - c[key] + (size) * (size - 1) / 2;
		cout << ans << endl;
	}

	return 0;
}

int main(void)
{
	while (solve())
	{
	}
	return 0;
}


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

int main(void){
    int N,A[200] = {0},ans,k;
    cin >> N;
    for(int size = 0;size < N;size++)cin >> A[size];
    for(ans = 0;A[0] % 2 == 0;A[0] /= 2,ans++);
    
    while( 1 ){
        for(int i = 1; i < N;i++){
            for(k = 0;A[i] % 2 == 0;A[i] /= 2,k++);
            if(ans > k)ans = k;
        }
        break;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    int K[N], P[N];
    for (int i = 0; i < N; i++) {
        cin >> K[i] >> P[i];
    }
    for (int i = 0; i < N; i++) {
        if (K[i] % P[i] == 0) {
            cout << P[i];
        } else {
            cout << K[i] % P[i];
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    string s;
    cin >> s;
    if(s.size()==2){
        if(s[0]==s[1]){
            cout << "1 2" << endl;
            return 0;
        }else{
            cout << "-1 -1" << endl;
            return 0;
        }
    }
    for(int i = 0; i < s.size()-2; i++){
        string s2 = s.substr(i,i+2);
        set<char> st = {s[i],s[i+1],s[i+2]};
        if(st.size() <= 2){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;

}


Measured memory_bytes: 512
from collections import deque

N, M = map(int, input().split())
hight = list(input().split())
hight = [int(hight[i]) for i in range(N)]


G = [deque([]) for i in range(N+1)] 

road = [input().split() for i in range(M)]

for i in range(M):
    G[int(road[i][0])].append(int(road[i][1]))
    G[int(road[i][1])].append(int(road[i][0]))   
    
count = 0


def dfs(v, num):
    while v:
        tmp = v.pop()
        if hight[tmp - 1] >= hight[num - 1]:
            return False
        else:
            continue
    
    return True

for i in range(N):
    if dfs(G[i+1], i+1):
        count += 1
    else:
        continue

print(count)

Measured memory_bytes: 112928
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8



int main(){
    ll N,K,a1=0,a2=0,ans;cin >> N >> K;
    if(K%2==0){
        a2=(N+K/2)/K;
    }
    a1=N/K;
    ans=a1*a1*a1+a2*a2*a2;
    cout << ans << endl;
}

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

public class MainClass
{
	public const long Giri = 1000000007;
	
	public static void Main(string[] args)
	{
		string[] rt = Input();
		int n = int.Parse(rt[0]);
		int a = int.Parse(rt[1]);
		int b = int.Parse(rt[2]);
		
		Console.WriteLine(Math.Min(a*n,b));
	}

	public static string[] Input()
	{
		return Console.ReadLine().Split(' ');
	}

	
	public static int Clamp(int val, int max, int min = 0)
	{
		return Math.Min(max, Math.Max(min, val));
	}

	
}



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

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
int MOD;

int power(int x, int t)
{
	int ret = 1;
	while(t > 0) {
		if(t & 1) ret = 1LL * ret * x % MOD;
		x = 1LL * x * x % MOD;
		t >>= 1;
	}
	return ret;
}

int n, m, k;
int fac[105], ifac[105];
int dp[105][105];

int pw[10005];
void mul_dp(int x, int dir)
{
	pw[0] = 1;
	rep1(i, n * m) pw[i] = 1LL * pw[i - 1] * x % MOD;
	
	if(dir == -1) for(int i = 0; i <= n; i ++) for(int j = 0; j <= m; j ++)
	dp[i][j] = 1LL * dp[i][j] * pw[n * m - (n - i) * (m - j)] % MOD;
	else for(int i = 0; i <= n; i ++) for(int j = 0; j <= m; j ++)
	dp[i][j] = 1LL * dp[i][j] * pw[i * j] % MOD;
}

void conv_dp(int coef)
{
	for(int i = n; i >= 0; i --) for(int j = 0; j <= m; j ++)
	rep(i0, i) if(coef == -1 && (i - i0 & 1))
	dp[i][j] = (dp[i][j] + 1LL * dp[i0][j] * (MOD - ifac[i - i0])) % MOD;
	else dp[i][j] = (dp[i][j] + 1LL * dp[i0][j] * ifac[i - i0]) % MOD;
	
	for(int i = 0; i <= n; i ++) for(int j = m; j >= 0; j --)
	rep(j0, j) if(coef == -1 && (j - j0 & 1))
	dp[i][j] = (dp[i][j] + 1LL * dp[i][j0] * (MOD - ifac[j - j0])) % MOD;
	else dp[i][j] = (dp[i][j] + 1LL * dp[i][j0] * ifac[j - j0]) % MOD;
}

int main()
{
	scanf("%d%d%d%d", &n, &m, &k, &MOD);
	
	fac[0] = 1;
	rep1(i, 100) fac[i] = 1LL * fac[i - 1] * i % MOD;
	rep(i, 101) ifac[i] = power(fac[i], MOD - 2);
	
	dp[0][0] = 1;
	
	for(int i = k; i >= 1; i --) {
		mul_dp(power(i, MOD - 2), 1);
		mul_dp(power((k - i + 1), MOD - 2), -1);
		if(i != k) {
			mul_dp(1LL * (k - i + 1) * power(k - i, MOD - 2) % MOD, -1);
			conv_dp(-1);
			mul_dp(1LL * (k - i) * power(k - i + 1, MOD - 2) % MOD, -1);
		}
		conv_dp(1);
		mul_dp((k - i + 1), -1);
		mul_dp(i, 1);
	}
	
	printf("%d\n", 1LL * fac[n] * fac[m] % MOD * dp[n][m] % MOD);
	return 0;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline

N = int(input())
l1, l2 = [], []

for _ in range(N):
    x, y = map(int, input().split())
    l1.append(x+y)
    l2.append(x-y)

print(max(max(l1)-min(l1), max(l2)-min(l2)))

Measured memory_bytes: 87704
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,m=parseMap(split(readline()))
    a=[parseInt(readline()) for i in 1:m]
    dp=zeros(Int,1,n+10)
    ok=Vector{Bool}([true for i in 1:n+10])
    for i in a
        ok[i]=false
    end
    dp[1]=1
    dp[2]=ifelse(ok[1],1,0)
    for i in 2:n+1
        if ok[i]
            dp[i+1]=(dp[i]+dp[i-1])%1000000007
        end
    end
    println(dp[n+1]%1000000007)
end
main()

Measured memory_bytes: 126728
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    string d[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;
    cin>>s;
    rep(i,7){
        if(s==d[i]){
            cout<<7-i<<endl;
        }
    }
}


Measured memory_bytes: 256
from collections import deque
from copy import copy

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

dxs = [0, 0, 1, -1]
dys = [1, -1, 0, 0]
cand = []
field_org = [-1] * (W * H)
for j in range(H):
    for i in range(W):
        if S[j][i] == '#':
            continue
        q = deque()
        q.append((i, j, 0))
        field = copy(field_org)
        field[j * W + i] = 0
        while q:
            p = q.popleft()
            for dx, dy in zip(dxs, dys):
                x, y = p[0] + dx, p[1] + dy
                f_idx = y * W + x
                if not (0 <= x < W) or not (0 <= y < H) or S[y][x] == '#' or field[f_idx] != -1:
                    continue
                field[f_idx] = p[2] + 1
                q.append((x, y, p[2] + 1))
        cand.append(max(field))
print(max(cand))


Measured memory_bytes: 3444
x,k,d = map(int,input().split())

cnt = -(-abs(x) // d)
if cnt > k:
    print(abs(x) - d * k)
else:
    k -= cnt
    if k % 2 == 0:
        print(abs(abs(x) - d * cnt))
    else:
        print(abs(abs(x) - d * (cnt - 1)))


Measured memory_bytes: 9120
#include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

int is_iwi(string s);

map<char, char> my_map;

int main(int argc, char const* argv[])
{
    string s;
    cin >> s;

my_map['i'] = 'i';
my_map['w'] = 'w';
my_map[' '] = ' ';
my_map['('] = ')';
my_map[')'] = '(';

    //char dir[5];
    //dir[0] = 'i';
    //dir[1] = 'w';
    //dir[2] = ' ';
    //dir[3] = ')';
    //dir[4] = '(';

    //if (is_iwi(s)) 
    //{
    //    cout << 0 << endl;
    //    return 0;
    //}

    int count=0; 
    int size=s.size();
    for (int i = 0; i < size / 2; i++) 
    {
        if ( my_map[s[i]] != s[size -1 -i] ) 
        {
            //iテァツ閉ェテァツ崢ョテ」ツ?古・ツッツセテァツァツーテ」ツ?ァテァツ?。テ」ツ?凝」ツ?」テ」ツ?淌」ツつ嘉」ツ??」ツつォテ」ツつヲテ」ツδウテ」ツδ?
            count++;
        }
    }
    if (size % 2 == 1) 
    {
        if (s[size/2] == 'i' || s[size/2] == 'w' || s[size/2] == ' ') 
        {
            
        }else{
            count++;
        }
    }
    cout << count << endl;
    return 0;

    //my_map<string, int> my_map;

    //queue<int> q;
    //while ( !q.empty() ) 
    //{
    //    //string::iterator ite=s.begin();
    //    //for (ite = s.begin(); ite < s.end(); ite++) 
    //    //{
    //    //    ite
    //    //}
    //    for (int i = 0; i < size / 2; i++) 
    //    {
    //        if ( my_map[s[i]] != s[size -1 -i] ) 
    //        {
    //            //iテァツ閉ェテァツ崢ョテ」ツ?古・ツッツセテァツァツーテ」ツ?ァテァツ?。テ」ツ?凝」ツ?」テ」ツ?淌」ツつ嘉」ツ??ゥツ??ァツ閉ェテ」ツ?ォティツゥツヲテ」ツ??
    //            for (int j = 0; j < 5; j++) 
    //            {
    //                
    //            } 
    //        }
    //    }
    //}
}

int is_iwi(string s)
{
    int size = s.size();
    for (int i = 0; i < size / 2; i++) 
    {
        if ( my_map[s[i]] != s[size -1 -i] ) {return 0;}
    }
    return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <string>

using namespace std;

int main() {
	string temp;
    int ct=0;
    while(1){
        getline(cin,temp);
        if(temp=="END OF INPUT"){break;}
        for(int i=0;i<temp.size();i++){
            if(temp.substr(i,1)==" "){
                cout << ct;
                ct=0;
            } else if(i==temp.size()-1){
            	cout << ct+1;
            	ct=0;
            } else {
            	ct++;
            }
        }
        cout << endl;
    }
}

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

int main(){
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	sort(arr.begin(),arr.end());
	reverse(arr.begin(),arr.end());
	if(arr[0]%2==0){
		long long mid = arr[0]/2;
		long long diff = numeric_limits<int>::max();
		long long sec;
		for(int i=1; i<arr.size(); i++){
			long long my_diff = abs(mid-arr[i]);
			if(my_diff<diff){
				diff = my_diff;
				sec = arr[i];
			}
		}
		cout<<arr[0]<<" "<<sec;
	}
	else{
		long long mid1 = arr[0]/2+1;
		long long mid2 = arr[0]/2;
		long long diff = numeric_limits<int>::max();
		long long sec=-1;
		for(int i=1; i<arr.size(); i++){
			int diff1 = abs(mid1-arr[i]);
			int diff2 = abs(mid2-arr[i]);
			if(diff1<diff){
				diff = diff1;
				sec = arr[i];
			}
			if(diff2<diff){
				diff = diff2;
				sec = arr[i];
			}
		}
		cout<<arr[0]<<" "<<sec;
	}
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    k--;
    int sum = (1+n)*n/2;
    if(k>=-1)
    {
        cout<<sum - 1 + (n-1)*k;//erase the first element
    }else
    {
        int num = abs(k);
        if(num > n)
            num = n;
        cout<< sum - num + (n-1)*k;//erase the num'th element
    }
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 500000

int main(){
  int i,n,a[N],temp,flag, count, childLarge;
  scanf("%d",&n);
  for(i = 1; i <= n; i++ ){
    scanf("%d",&a[i]);
  }

  count = 1;
  while(count>0){
    count = 0;
    for(i = n/2; i > 0; i--){
      if(a[i*2+1]>a[i*2]){
        childLarge = i*2+1;
      }else{
        childLarge = i*2;
      }

      if(a[i]<a[childLarge]){
        temp = a[i];
        a[i] = a[childLarge];
        a[childLarge] = temp;
        count++;
      }
    }
  }

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

  return 0;
}

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

int divi(int x, int y){
  if(x % y == 0) return y;
  
  x %= y;
  return divi(y, x);
}

int main(){
  int k;
  cin >> k;
  
  long long ans = 0;
  for(int a = 1; a <= k; ++a){
    for(int b = 1; b <= k; ++b){
      for(int c = 1; c <= k; ++c){
        ans += divi(divi(a, b), c);
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3640
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n=0,d=0) Array.new(n,d)end
def na2(n=0,m=0,d=0) Array.new(n){Array.new(m,d)}end
def na3(n=0,m=0,l=0,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n,k = inp
lis = na(10**5)
n.times do
  a,b = inp
  lis[a-1] += b
end
lis.each.with_index(1) do |num, ans|
  k -= num
  if(k <= 0)
    puts ans
    exit 
  end 
end

=begin
=end

Measured memory_bytes: 2556
#include <iostream>
#include <vector>
using namespace std;
typedef long long Long;
#define INF 1000000001
vector<int> vecIn;

Long MergeSort(vector<int>* pvecIn, int nLeft, int nMid, int nRight)
{
	Long lRet = 0;
	int nl = nMid - nLeft;
	int nr = nRight - nMid;
	vector<int> vecLeft(nl + 1, INF);
	vector<int> vecRight(nr + 1, INF);

	for (int i = 0; i < nl; ++i)
	{
		vecLeft[i] = (*pvecIn)[nLeft + i];
	}
	for (int i = 0; i < nr; ++i)
	{
		vecRight[i] = (*pvecIn)[nMid + i];
	}
	int k = 0, i = 0, j = 0;
	for (k = nLeft; k < nRight; ++k)
	{
		if (vecLeft[i] < vecRight[j])
		{
			(*pvecIn)[k] = vecLeft[i];
			++i;
		}
		else
		{
			(*pvecIn)[k] = vecRight[j];
			++j;
			lRet += nl - i;
		}
	}
	return lRet;
}


Long Merge(vector<int>* pvecIn, int nLeft, int nRight)
{
	int nMid = 0;
	Long L1, L2, L3;
	if (nLeft + 1 < nRight)
	{
		nMid = (nLeft + nRight) / 2;
		L1 = Merge(pvecIn, nLeft, nMid);
		L2 = Merge(pvecIn, nMid, nRight);
		L3 = MergeSort(pvecIn, nLeft, nMid, nRight);
		return L1 + L2 + L3;
	}
	else
	{
		return 0;
	}
}


int main()
{
	//vector<int> vecIn;
	int nIn;
	cin >> nIn;
	int nTemp = 0;
	for (int i = 0; i < nIn; ++i)
	{
		cin >> nTemp;
		vecIn.push_back(nTemp);
	}
	Long lRet = 0;
	lRet = Merge(&vecIn, 0, nIn);
	cout << lRet << endl;
	//system("pause");
	return 0;
}


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

const int inf = 1e9+7;
int a[100007];
int n;
long long ans;

int main(){
	
	cin >> n;
	for(int i = 2;i<=n;i++){
		int x = i;
		for(int j = 2;j<=sqrt(n);j++){
			while(x%j==0){
				a[j]++;
				x/=j;
			}
		}
		if(x>1) a[x]++;
	}
	ans = 1;
	for(int i = 2;i<=n;i++){
		if(a[i]){
			ans*=(a[i]+1)%inf;
			ans%=inf;
		}
	}
	cout << ans;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

    vint dp(N+1,N);
    dp[0]=0;
    for(int i=0;i<N;i++){
        for(int j=1;i+j<=N;j*=6){
            dp[i+j]=min(dp[i+j],dp[i]+1);
        } 
        for(int j=1;i+j<=N;j*=9){
            dp[i+j]=min(dp[i+j],dp[i]+1);
        }
    }
    cout<<dp[N]<<endl;

}


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

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

  int t = 0;
  if (A < 0) {
    t += -A * C + D;
    A = 0;
  }
  t += (B - A) * E;

  cout << t << endl;
}



Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int main()
{
    int n, a, o = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        scanf("%d", &a);
        if(a % 2 != 0) o++;
    }
    cout << (o % 2 == 0 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a[4];
  int b[4]={1,4,7,9};
  rep(i,4) cin>>a[i];
  sort(a,a+4);
  rep(i,4){
    if(a[i]!=b[i]){cout<<"NO"<<endl;return 0;}
  }
  cout<<"YES"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  map<string, int> mp;

  char s_str, s_end;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    mp[s]++;

    if (i != 0) {
       s_str = s.at(0);
       if (s_str != s_end) {
         cout << "No" << endl;
         return 0;
       }
    }

    s_end = s.at(s.size() - 1);

  }
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    if (itr->second != 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int ddx[6]={0,1,0,-1,1,-1},ddy[6]={-1,0,1,0,1,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
string s[12];
int ca[10];//alphabet-num
char c[10];//alphabet
int nc;// how many alphabet
int sk[10];//firts number or not
int nsk;//how many ↑
int plu[10];
int w[8]={1,10,100,1000,10000,100000,1000000,10000000};
int re_ans=0;
int nm_alr[10]={};

void dfs(int p){
	if(p==nc){
		int ans=0;
		REP(i,nc){
			ans+=plu[i]*ca[i];
		}
		if(ans==0){
			re_ans++;
			
		}
		return;
	}
	for(int i=0;i<10;i++){
		if(nm_alr[i]==1)continue;
		if(i==0&&sk[p])continue;
		ca[p]=i;
		nm_alr[i]=1;
		//cout<<"3"<<endl;
		dfs(p+1);
		nm_alr[i]=0;
	}
	return;
}
vector<int> rere_ans;
int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		nc=0;
		re_ans=0;
		nsk=0;
		nc=0;
		REP(i,10)nm_alr[i]=0;
		REP(i,n)
			cin>>s[i];
		REP(i,n){
			REP(j,s[i].size()){
				for(int k=0;k<nc;k++){
					if(c[k]==s[i][j])goto A;
				}
				c[nc++]=s[i][j];
				A:;
			}
		}
		//cout<<nc<<endl;
		REP(i,10)plu[i]=0;
		REP(i,n-1){
			REP(j,s[i].size()){
				int tt=s[i].size()-j-1;
				for(int k=0;k<nc;k++){
					if(c[k]==s[i][j]){
						plu[k]+=w[tt];
						break;
					}
				}
			}
		}
		REP(j,s[n-1].size()){
			int tt=s[n-1].size()-j-1;
			for(int k=0;k<nc;k++){
				if(c[k]==s[n-1][j]){
					plu[k]=plu[k]-w[tt];
					break;
				}
			}
		}
		REP(i,10)sk[i]=0;
		REP(i,n){
			if(s[i].size()==1)continue;
			REP(j,nc){
				if(c[j]==s[i][0])sk[j]=1;
			}
		}
		//REP(i,nc)cout<<c[i]<<" "<<plu[i]<<endl;
		dfs(0);
		rere_ans.push_back(re_ans);
	}
	REP(i,rere_ans.size())cout<<rere_ans[i]<<endl;
	return 0;
}


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

void print( int h, int w ) {
	for( int y = 0; y < h; ++y ) {
		string s = (y & 1 ? ".#" : "#.");

		for( int x = 0; x < w; ++x ) {
			cout << s[x & 1];
		}

		cout << endl;
	}
}

int main() {
	for( ;; ) {
		int H, W;
		cin >> H >> W;

		if( H == 0 && W == 0 ) {
			break;
		}

		print( H, W );
		cout << endl;
	}
}



Measured memory_bytes: 3208
#include <stdio.h>

int main()
{   
    int a,b;
    scanf("%d%d",&a,&b);
    if(a<=0&&b>=0){
    printf("Zero");
    return 0;
    }
    if(a>0){
        printf("Positive");
        return 0;
    }
    if((b-a+1)%2==0){
        printf("Positive");
    }else{
        printf("Negative");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const double PI = 3.14159265358979323846;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main(void) {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  combination c(n + k);
  mint ans = 0;
  for (int i = 0; i <= k; i++) {
    mint x = mint(26).pow(k - i);
    x *= mint(25).pow(i);
    x *= c(n - 1 + i, n - 1);
    ans += x;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 35592
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define umap unordered_map
#define RESET   "\033[0m"
#define RED     "\033[31m"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const ll lINF = 1e18+7;
const int INF = 1e9+7;

template <class T> ostream& operator<<(ostream& s, const vector<T>& v) {
    for (size_t i = 0; i < v.size(); i++) s << v[i] << ' ';
    return s;
}

template <class T> istream& operator>>(istream& s, vector<T>& v) {
    for (size_t i = 0; i < v.size(); i++) s >> v[i];
    return s;
}


//########################################################################################


int n, m, k, ans = 0;


void rec2(int idx, vector<string> v, int cnt) {
	if (idx == m) {
		if (cnt == k) ans++;
		return;
	}
	rec2(idx+1, v, cnt);
	for (int j = 0; j < n; j++) {
		if (v[j][idx] == '#') {
			cnt--;
			v[j][idx] = '.';
		}
	}
	rec2(idx+1, v, cnt);
}

void rec(int idx, vector<string> v, int cnt) {
	if (idx == n) {
		rec2(0, v, cnt);
		return;
	}
	rec(idx+1, v, cnt);
	for (int j = 0; j < m; j++) {
		if (v[idx][j] == '#') {
			cnt--;
			v[idx][j] = '.';
		}
	}
	rec(idx+1, v, cnt);
}


void solve(int CASE=0) {
	cin >> n >> m >> k;
	vector<string> v(n);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		for (int j = 0; j < m; j++) 
			if (v[i][j] == '#') cnt++;
	}
	rec(0, v, cnt);
	cout << ans;
}


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

    int TEST = 1;
    //cin >> q;
    for (int i = 1; i <= TEST; i++) 
		solve(i);
}


Measured memory_bytes: 3616
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a, const void *b)
{
    long *A = (long int *)a;
    long *B = (long *)b;
    if (*A > *B)return 1;
    if (*A < *B)return -1;
    return 0;
}
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    long a[200005];
    for (i = 0; i < n; i++)
        scanf("%ld", &a[i]);
    long sum[200005];
    sum[0] = 0;
    for (i = 0; i < n; i++)
        sum[i + 1] = sum[i] + a[i];
    qsort(sum, n + 1, sizeof(long), asc);
    unsigned long long int ans = 0, x;
    x = 1;
    for (i = 1; i < n + 1; i++)
    {
        if (sum[i] == sum[i - 1])
            x++;
        else
        {
            ans += x * (x - 1) / 2;
            x = 1;
        }
    }
    ans += x * (x - 1) / 2;
    printf("%lld\n", ans);
    return 0;
}

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

int main(int argc, const char * argv[]) {
    int a,b,c;
    string str;
    cin >> a >> b >> c ;
   
    if(a<b && b<c){
        str = "Yes";
    }else{
    str = "No";
    }

    cout << str  << endl;
return 0;
}

Measured memory_bytes: 1192
from itertools import permutations, combinations, combinations_with_replacement

# balls = [1,2,3]
#print(list(permutations(balls, 2))) #順列
#print(list(combinations(balls, 2))) #組み合わせ

n, m, q = map(int, input().split())
a = []
b = []
c = []
d = []

for i in range(q):
  A, B, C, D = map(int, input().split())
  a.append(A)
  b.append(B)
  c.append(C)
  d.append(D)

ans = 0
nums = range(1, m + 1)

for retsu in combinations_with_replacement(nums, n):
    # print(retsu)
    point = 0
    for i in range(q):
        if retsu[b[i] - 1] - retsu[a[i] - 1] == c[i]:
            point += d[i]
            # print(retsu)
    if ans < point:
        # print(retsu)
        ans = point

print(ans)
    

Measured memory_bytes: 67904