akhauriyash/Code-Regression huggingface dataset:
#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>;

const int INF=1001001001;

int main(){
    int n,m;
    cin>>n>>m;
    vector<P>x(m);
    rep(i,m){
        int a,b; cin>>a>>b;
        x[i]=P(a,b);
    }
    sort(x.begin(),x.end());
    int mn=-1,mx=INF,ans=0;
    rep(i,m){
        mn=max(mn,x[i].first);
        mx=min(mx,x[i].second);
        if(mn>=mx){
            ans++;
            mn=x[i].first;
            mx=x[i].second;
        }
    }
    ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 4064
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 2018-11-4 21:02:12
# Powered by Visual Studio Code
#

n = gets.to_i
@t, a = gets.chomp.split(" ").map{|i| i.to_i}
h = gets.chomp.split(" ").map{|i| i.to_f}

def th(x)
  return @t - x * 0.006
end

ans = []

for i in 0...n do
  ans << [(a - th(h[i])).abs, i]
end

puts (ans.min)[1] + 1



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

int main(){
	int n, max, min, kkk;
	cin >> n;
	for(int i=0;i<n;i++){
		string input ="", mmm, mai="",mii="";
		int a[8] = {};
		cin >> input;
		for(int j = 0;j<8;j++){
			mmm = input[j];
			a[j] = stoi(mmm);
		}
		sort(a, end(a));
		kkk = 0;
		for (int j = 0; j<8; j++) {
			if(a[7]==0){
				mai = "0";
				mii = "0";
				break;
			}
			mai += to_string(a[7 - j]);
			if (a[j] == 0 && kkk == 0) {}
			else{
				mii += to_string(a[j]);
				kkk++;
			}
		}
		max = stoi(mai);
		min = stoi(mii);
		cout << max - min << endl;
	}
	return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
}


Measured memory_bytes: 256
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end


r = gets.to_i

puts 2 * PI * r

Measured memory_bytes: 14344
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  rep(i, s.size()) {
    if(i % 2 == 0) cout << s[i];
  }
  cout << endk;
  return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>          
using namespace std;
typedef long long ll;

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

    vector<ll> ans(N);
    for (ll i=0; i<N; i++) {
        ans[i] = sum^A[i];
    }
    for (ll i=0; i<N; i++) {
        cout << ans[i] << ' ';
    }
    cout << endl;
}

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

int cnt=0; 

void f(vector<int>& a){
    if(a[0]==a[1] && a[1]==a[2]) cout<<cnt<<"\n";
    else{
        sort(a.begin(),a.end());
        if(a[1]-a[0]>=2){
            a[0]+=2;
        }
        else{
            a[0]++;
            a[1]++;
        }
        cnt++;
        f(a);
    }
}

int main(){
    vector<int> a(3);
    rep(i,3) cin>>a[i];
    f(a);
    //cout<<cnt<<"\n";

    return 0;
}

Measured memory_bytes: 3600
n=int(input())

x=[-1]*(n+1) #2以上の自然数に対して最小の素因数を表す
x[0]=0
x[1]=1
i=2
prime=[]
while i<=n:
    if x[i]==-1:
        x[i]=i
        prime.append(i)
    for j in prime:
        if i*j>n or j>x[i]:break
        x[j*i]=j
    i+=1

def f(k):
    z=[]
    if k==1:
        return 1
    p=x[k]
    c=1
    while k>1:
        if p!=x[k//p]:
            z.append(c)
            c=1
        else:
            c+=1

        k=k//p
        p=x[k]

    ans=1
    for i in range(len(z)):
        ans=ans*(z[i]+1)
    return ans
s=0
for i in range(n):
    s+=(i+1)*f(i+1)
print(s)



Measured memory_bytes: 194284
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n,m; cin >> n >> m;
    vector<int> cnt(n,0);
    vector<bool> ac(n, false);
    int ans = 0, pen = 0;
    
    while(m--){
        int p; string s; cin >> p >> s; --p;
        if(s == "AC"){
            if(!ac[p]){
                ac[p] = true;
                ++ans;
                pen += cnt[p];
            }
        }
        else{
            ++cnt[p];
        }
    }
    cout << ans << ' ' << pen << '\n';
    return 0;
}

Measured memory_bytes: 640
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	X = int(N / 1.08 // 1)
	#print(X)
	if int(X * 1.08 // 1) == N:
		print(X)
		return

	if int((X - 1) * 1.08 // 1) == N:
		print(X - 1)
		return

	if int((X + 1) * 1.08 // 1) == N:
		print(X + 1)
		return

	print(":(")


if __name__ == '__main__':
	main()

Measured memory_bytes: 3444
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

N = k()
A = l()
for i in A:
    ans += 1/i
 
ans = 1/ans
print(ans)

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

int n;
long long a[200000];
long long b[200000];
long long sum;

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		sum += a[i];
		a[i] *= 2; 
	} 
	for(int i=1;i<n-1;i += 2)
		sum -= a[i];
	b[0]=sum;
	for(int i=1;i<n;i++)
	{
		b[i]=a[i-1]-b[i-1];
	}
	for(int i=0;i<n;i++)
		cout << b[i] << ' ';
	return 0;
}

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

int main() {
  int N, M;
  cin >> N;
  
  vector<string> str;
  vector<int> num;
  string temp;
  
  cin >> temp;
  str.push_back(temp);
  num.push_back(1);
  
  bool f = 0;
  
  for (int i = 0; i < N - 1; i++) {
    f = 0;
    cin >> temp;
    for (int j = 0; j < str.size(); j++) {
      if (temp == str.at(j)) {
        num.at(j)++;
        f = 1;
        break;
      }
    }
    if (f == 0) {
      str.push_back(temp);
      num.push_back(1);
    }
  }
  
  cin >> M;
  
  for (int i = 0; i < M; i++) {
    cin >> temp;
    for (int j = 0; j < str.size(); j++) {
      if (temp == str.at(j)) {
        num.at(j)--;
        break;
      }
    }
  }
  
  int m = 0;
  
  for (int i = 0; i < num.size(); i++) {
    if (m < num.at(i)) {
      m = num.at(i);
    }
  }
  
  cout << m << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq; 

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
string S=Console.ReadLine();
    string T=Console.ReadLine();
      int ans=S.Length;
       //Sの何文字目から調べるかを全探索する
    for (int start = 0; start <= S.Length - T.Length; start++)
    {
        int diff = 0;
        for (int i = 0; i < T.Length; i++)
        {
            if (T[i] != S[start + i]) {
                diff++;
            }
        }
        ans = Math.Min(ans, diff);
    }
      Console.WriteLine(ans);
    }
    
  }

}

Measured memory_bytes: 25920
#include <iostream>

int main(){
  std::string s;
  std::cin >> s;
  bool flg = false;
  for(const auto &i : s) {
    if (i=='C') {
      flg = true;
      continue;
    }
    if (i=='F' && flg) {
      std::cout << "Yes";
      return 0;
    }
  }
  std::cout << "No";
  return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	vector <int> d(5);
	for (int ii = 0; ii < 5; ++ii){
		cin >> d[ii];
	}

	int k;
	cin >> k;

	bool ok = true;
	for (int ii = 0; ii < 4; ++ii){
		for (int jj = ii + 1; jj < 5; ++jj){
			if (abs(d[ii]-d[jj]) > k){
				ok = false;
			}
		}
	}

	if (ok){
		cout << "Yay!" << "\n";
	} else {
		cout << ":(" << "\n";
	}


	return 0;
}


Measured memory_bytes: 3576
_,s=open(0)
dp=[[0]*1000for _ in range(4)]
dp[0][0]=1
for c in map(int,s[:-1]):
  for i in range(3,0,-1):
    for j in range(10**(i-1)):
      dp[i][j*10+c]|=dp[i-1][j]
print(sum(dp[3][i]for i in range(1000)))

Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
	int i, j;
	int a1, a2, a3;
	
	scanf("%d", &j);
	
	for (i = 0; i < j; i++){
		scanf("%d %d %d", &a1, &a2, &a3);
		a1 *= a1;
		a2 *= a2;
		a3 *= a3;
		if ((a2 < a1) && (a3 < a1)){
			if (a1 == (a2 + a3)){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
		else if ((a1 < a2) && (a3 < a2)){
			if (a2 == (a1 + a3)){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
		else {
			if (a3 == (a1 + a2)){
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<int,Pil>Piil;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
ll a[100001];

int main() {

	int n;
	cin>>n;

	rep(i,n)cin>>a[i];

	ll x=a[n/2],m=a[0],u=a[n-1];
	for(int i=1; i<n/2; i++)m=a[i]-m;
	for(int i=n-2; i>n/2; i--)u=a[i]-u;
	x=x-m-u;

	if((n-1)%4==0)x/=2;
	else x/=-2;

	cout<<2*x<<" ";
	for(int i=0; i<n-2; i++){
		x=a[i]-x;
		cout<<2*x<<" ";
	}
	cout<<2*(a[n-2]-x)<<endl;

	return 0;
}


Measured memory_bytes: 4348
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

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

int main() {

    ll Q;
    cin >> Q;
    ll max = 100000;
    bool A[max+1];
    rep(i,max+1){
        if(i<=1||(i!=2&&i%2==0)) A[i] = false;
        else A[i] = true;
    }
    for(ll i=1;i<=max;i++){
        if(i%2==1){
            for(ll j=1;j<=sqrt(i);j++){
                if(j!=1&&i%j==0){
                    A[i] = false;
                    break;
                }
            }
        }
    }
    ll B[max+1];
    rep(i,max+1) B[i] = 0;
    ll C[max+1];
    rep(i,max+1) C[i] = 0;
    ll cnt = 0;
    rep(i,max+1){
        if(i>1&&i%2==1){
            if(A[i]==true&&A[(i+1)/2]==true){
                cnt++;
                C[i]++;
            }
            B[i] = cnt;
        }
    }
    rep(i,Q){
        ll l,r;
        cin >> l >> r;
        cout << B[r]-B[l]+C[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 2304
import java.util.*;

public class Main {
	static double dp[][][];

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		dp = new double[301][301][301];
		for (int i = 0; i <= 300; i++) {
			for (int j = 0; j <= 300; j++) {
				for (int z = 0; z <= 300; z++) {
					dp[i][j][z] = -1;
				}
			}
		}

		int x = 0;
		int y = 0;
		int z = 0;

		for (int i = 0; i < n; i++) {
			int val = scn.nextInt();
			if (val == 1) {
				x++;
			} else if (val == 2) {
				y++;
			} else {
				z++;
			}
		}
		dp[0][0][0] = 0;
		solve(x, y, z, n);
		System.out.println(dp[x][y][z]);
	}

	private static double solve(int x, int y, int z, int n) {
		if (x < 0 || y < 0 || z < 0) {
			return 0;
		}
		if (dp[x][y][z] > -1) {
			return dp[x][y][z];
		}
		double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n);
		dp[x][y][z] = exp / (x + y + z);

		return dp[x][y][z];
	}
}

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

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

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

  vector<string> s(n);
  rep(i,n) cin >> s.at(i);

  vector<int> alp(26,100);
  rep(k,26){
    if(alp.at(k)==0) continue;
    rep(i,n){
      int count=0;
      rep(j,s.at(i).size()){
        int now = (int)s.at(i).at(j) - 97;
        if(k==now) count++;
      }
      alp.at(k) = min(alp.at(k), count);
    }
  }

  rep(i,26){
    rep(j,alp.at(i)) cout << char(i+97);
  }
}

Measured memory_bytes: 3588
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp::max;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let s = scan.chars();
    let n = s.len();
    let mut dp = vec2(n+1, 3, -1i64 << 60);
    dp[0][0] = 0;
    for i in 0..n { for j in 0..3 {for d in 1..3 { if i+d<dp.len() && dp[i][j] >= 0 {
        if j == d {
            if d == 1 {if s[i-1] == s[i] {continue}}
            else if s[i-2] == s[i] && s[i-1] == s[i+1] {continue}
        }
        let tmp = dp[i][j];
        chmax(&mut dp[i+d][d], tmp + 1);
    }}}}
    println!("{}", max(dp[n][1], dp[n][2]));
}

#[allow(dead_code)]
fn chmax<T: PartialOrd>(a: &mut T, b: T) -> bool {
    if *a < b {
        *a = b;
        true
    } else { false }
}

#[allow(dead_code)]
fn chmin<T: PartialOrd>(a: &mut T, b: T) -> bool {
    if *a > b {
        *a = b;
        true
    } else { false }
}

#[allow(dead_code)]
fn vec2<T: Clone>(a: usize, b: usize, init: T) -> Vec<Vec<T>> {
    vec![vec![init;b];a]
}

#[allow(dead_code)]
fn vec3<T: Clone>(a: usize, b: usize, c: usize, init: T) -> Vec<Vec<Vec<T>>> {
    vec![vec![vec![init;c];b];a]
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut ret = vec![];
        for _ in 0..n { ret.push(self.read::<T>()) }
        ret
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 16636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long ans = 0;
        long tmp = a * (n / (a + b));
        long tmp2 = Math.min(a, n % (a + b));
        System.out.println(tmp + tmp2);
    }
}

Measured memory_bytes: 35748
#include <iostream>
#include <bits/stdc++.h>
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define vii vector<pair<int, int> >
#define si stack<int>
#define pb push_back
#define mp make_pair
#define ALL(T) (T).begin(), (T).end()
#define MODU 1000000007
typedef long long ll;
using namespace std;

ll intmax = (1LL<<32)-1;
ll llmax = (1LL<<60)-1;

const int INF = 1e9 + 5;

class fastio{
public:
	fastio(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	}
} __fastio;

template <typename T>
T abs(T x){
	if(x<0)	return -x;
	else return x;
}

void DFSVisit(int u, vector<int> g[], vector<bool> &visited){ 
    visited[u] = true;
    for(int i=0; i<(int)(g[u].size()); i++){
        if(!visited[g[u][i]]){
            DFSVisit(g[u][i], g, visited); 
        }
    }
} 
  
void DFS(vector<int> adj[], int V){
    vector<bool> visited(V, false); 
    for(int u=0; u<V; u++) 
        if(!visited[u]) 
            DFSVisit(u, adj, visited);
}


void solve() {

}

int dp[1005][1005];
char grid[1005][1005];
int main() {
	int h,w;
	cin >> h >> w;
	dp[0][0] = 1;
	for(int i=0; i<h; i++) {
		for(int j=0; j<w; j++)
			cin >> grid[i][j];
	}
	for(int i=1; i<h; i++) {
		if(grid[i][0] == '#')
			dp[i][0] = 0;
		else
			dp[i][0] = dp[i-1][0];
	}
	for(int i=1; i<w; i++) {
		if(grid[0][i] == '#')
			dp[0][i] = 0;
		else
			dp[0][i] = dp[0][i-1];
	}
	for(int i=1; i<h; i++) {
		for(int j=1; j<w; j++) {
			if(grid[i][j] == '#')
				dp[i][j] = 0;
			else
				dp[i][j] = (dp[i-1][j] + dp[i][j-1] ) % MODU;
		}
	}
	cout << dp[h-1][w-1] << endl;
}


Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

vector<int> perm_comp(vector<int> a, vector<int> b) {
	int n = b.size();
	vector<int> res(n);
	rep(i, n) res[i] = a[b[i]];
	return res;
}

vector<int> perm_pow(vector<int> base, int k) {
	int n = base.size();
	vector<int> ans(n);
	rep(i, n) ans[i] = i;
	while (k) {
		if (k & 1) ans = perm_comp(ans, base);
		base = perm_comp(base, base);
		k >>= 1;
	}
	return ans;
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	vector<int> x(n);
	rep(i, n) cin >> x[i];
	int m, k;
	cin >> m >> k;
	vector<int> a(m);
	rep(i, m) cin >> a[i];
	vector<int> d(n - 1);
	rep(i, n - 1) d[i] = x[i + 1] - x[i];
	vector<int> ans(n - 1);
	rep(i, n - 1) ans[i] = i;
	rep(i, m) swap(ans[a[i] - 2], ans[a[i] - 1]);
	ans = perm_pow(ans, k);
	int res = x[0];
	cout << res << endl;
	rep(i, n - 1) {
		res += d[ans[i]];
		cout << res << endl;
	}
}

Measured memory_bytes: 7360
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

long gdc(long x, long y) {
  auto m = std::max(x, y);
  auto n = std::min(x, y);
  long tmp;
  while (m % n) {
    tmp = n;
    n = m % n;
    m = tmp;
  }
  return n;
}

long count(long a, long b, long x) {
  return b / x - a / x + (a % x == 0 ? 1 : 0);
}

long solve(long a, long b, long c, long d)
{
  return b - a + 1 - count(a, b, c) - count(a, b, d) + count(a, b, c * d / gdc(c, d));
}

int main()
{
  long a, b, c, d;
  std::cin >> a >> b >> c >> d;

  std::cout << solve(a, b, c, d) << std::endl;
}


Measured memory_bytes: 256
import math

def triangle(a, b, deg):
    result = {}
    rad = math.radians(deg)
    c = math.sqrt(a*a+b*b-(2*a*b*math.cos(rad)))
    s = (a+b+c)/2
    result['area'] = math.sqrt(s*(s-a)*(s-b)*(s-c))
    result['perimeter'] = a+b+c
    result['height'] = result['area'] * 2 / a
    return result

if __name__ == '__main__':
    a, b, deg = map(int, input().split())
    triangle = triangle(a, b, deg)
    print(triangle['area'])
    print(triangle['perimeter'])
    print(triangle['height'])



Measured memory_bytes: 5712
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int[] dist = new int[k];
    for(int i = 0; i < k; i++) {
      dist[i] = Integer.MAX_VALUE;
    }
    dist[1] = 0;
    Deque<Integer> deque = new ArrayDeque<>();
    deque.addFirst(1);
    int[] visit = new int[k];
    visit[1] = 1;
    while(deque.size() > 0) {
      int u = deque.pollFirst();
      int v1 = (10 * u) % k;
      int v2 = (u + 1) % k;
      if(visit[v1] == 0)  {
        dist[v1] = Math.min(dist[v1], dist[u]);
        deque.addFirst(v1);
        visit[v1] = 1;
      } else {
        if(dist[v1] > dist[u]) {
          dist[v1] = dist[u];
          deque.addFirst(v1);
        }
      }
      if(visit[v2] == 0) {
        dist[v2] = Math.min(dist[v2], dist[u] + 1);
        deque.addLast(v2);
        visit[v2] = 1;
      }
    }
    System.out.println(dist[0] + 1);
  }
}


Measured memory_bytes: 26796
N, M = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]


import numpy as np
y = np.array(x)

y1 = np.copy(y)
y1[:, 0] = y1[:, 0] * -1

y2 = np.copy(y)
y2[:, 0] = y2[:, 0] * -1
y2[:, 1] = y2[:, 1] * -1

y3 = np.copy(y)
y3[:, 0] = y3[:, 0] * -1
y3[:, 1] = y3[:, 1] * -1
y3[:, 2] = y3[:, 2] * -1

y4 = np.copy(y)
y4[:, 1] = y4[:, 1] * -1

y5 = np.copy(y)
y5[:, 1] = y5[:, 1] * -1
y5[:, 2] = y5[:, 2] * -1

y6 = np.copy(y)
y6[:, 2] = y6[:, 2] * -1

y7 = np.copy(y)
y7[:, 0] = y7[:, 0] * -1
y7[:, 2] = y7[:, 2] * -1

if M != 0:
    print(np.max([np.sum(np.sort(np.sum(y, axis=1))[-1 * M:]),
                 np.sum(np.sort(np.sum(y1, axis=1))[-1 * M:]),
                 np.sum(np.sort(np.sum(y2, axis=1))[-1 * M:]),
                 np.sum(np.sort(np.sum(y3, axis=1))[-1 * M:]),
                 np.sum(np.sort(np.sum(y4, axis=1))[-1 * M:]),
                 np.sum(np.sort(np.sum(y5, axis=1))[-1 * M:]),
                 np.sum(np.sort(np.sum(y6, axis=1))[-1 * M:]),
                 np.sum(np.sort(np.sum(y7, axis=1))[-1 * M:])]))
else:
    print(0)


Measured memory_bytes: 14692
#include <bits/stdc++.h>
#define var auto
using ll = long long;
const char newl = '\n';
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {if(a > b) a = b;}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {if(a < b) a = b;}

using namespace std;
struct UnionFind{
    int num;
    vector<int> r,p;
    UnionFind(){}
    UnionFind(int n):num(n), r(n, 1), p(n, 0){iota(p.begin(), p.end(),0);}
    int find(int x){
        return (x==p[x] ? x : p[x] = find(p[x]));
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    void unite(int x, int y){
        x=find(x);y=find(y);
        if (x == y) return;
        if (r[x] < r[y]) swap(x, y);
        r[x] += r[y];
        p[y]=x;
        num--;
    }
    int size(int x){
        return r[find(x)];
    }
    int count() const{
        return num;
    }
};

void solver(int n, int m) {

    struct edge {
        int s, t, c;
        edge() {}
        edge(int s, int t, int c) : s(s), t(t), c(c) {}
    };

    vector< edge > edges;
    for (int i = 0; i < m; i += 1) {
        int s, t, c;
        cin >> s >> t >> c;
        s--; t--;

        edges.emplace_back(s, t, c);
    }

    sort(edges.begin(), edges.end(), [](edge a, edge b) { return a.c < b.c; });

    vector< int > ans;
    UnionFind uf(n);

    for (auto e: edges) {
        if (uf.same(e.s, e.t)) continue;
        ans.push_back(e.c);
        uf.unite(e.s, e.t);
    }

    cout << ans[(n - 1) / 2] << endl;
    
}

signed main() {
    int n, m;
    
    while (cin >> n >> m, n) {
        solver(n, m);
    }
}





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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a-c) <= d){
        cout << "Yes" << endl;
    }
    else if(abs(a-b) <= d && abs(b-c) <= d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
class Array
  def sum
    result = 0
    self.each { |x| result += x }
    result
  end
end
n = gets.to_i
b = gets.split.map(&:to_i)
a = []
(0..n-1).each do |i|
  if i == 0 
    a[i] =  b[i]
  elsif i == n - 1
    a[i] = b[i - 1]
  else
    a[i] = [b[i], b[i - 1]].min
  end
end
puts a.sum


Measured memory_bytes: 1788
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<int> c(N);
  vector<int> s(N);
  vector<int> f(N);
  vector<long long int> sum(N, 0);
  for (int i = 0; i < N - 1; i++) {
    cin >> c[i] >> s[i] >> f[i];
  }

  for (int j = 0; j < N - 1; j++) {
    for (int i = j; i < N - 1; i++) {
      if (sum[j] < s[i]) {
        sum[j] = s[i];
        sum[j] += c[i];
      } else {
        for (int k = 1; k <= 100; k++) {
          if (sum[j] % f[i] == 0) {
            sum[j] += c[i];
            break;
          } else {
            sum[j]++;
          }
        }
      }
      // cout << i << ":" << sum[j] << endl;
    }
  }

  for (int i = 0; i < sum.size(); i++) {
    cout << sum[i] << endl;
  }
  return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}

using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s<<'[';for(size_t i=0;i<v.size();++i){s << v[i];if(i < v.size()-1) s << ", ";}s<<']';return s;
}

int main(){

    int n, m;
    scanf("%d%d", &n, &m);
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    stack<int> res;
    for(int i = 0; i < n; ++i){
        if(n-i <= m) {
            res.emplace(n-i);
            break;
        }
        bool ok = false;
        for(int j = m; j > 0; --j){
            eee(i+j);
            if(i+j > n+1) {ppp(-1);return 0;}
            if(s[i+j] == '0'){
                res.emplace(j);
                i += j-1;
                ok = true;
                break;
            }
        }
        if(!ok){
            ppp(-1);
            return 0;
        }
    }

    while(!res.empty()){
        int x = res.top(); res.pop();
        printf("%d ", x);
    }
    putchar('\n');

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  
    return true;
  }
  return false;
}
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N,K;
    ll mincost = INF;
    cin >>N>>K;
    vector<ll> a(N);
    vector<ll> b(N);
    rep(i,N){
        cin >> a[i];
    }
    b = a;
    rep(bit,1<<N){
        vector<ll> S;
        vector<ll> T;
        rep(i,N){
            if(bit&(1<<i)){
                S.pb(1);
                T.pb(i);
            }else{
                S.pb(0);
            }
        }
        ll mx = 0;
        ll cost = 0;
        
        if(T.size() >= K){
            rep(i,N){
                if(S[i] == 1){
                    if(a[i] > mx){
                        mx = a[i];
                    }else{
                        cost +=  mx +1-a[i];
                        mx ++;
                    }
                }else{
                    chmax(mx,a[i]);
                }
                
            }
            chmin(mincost,cost);
        }

    }
    cout << mincost << endl;
    
    
    return 0;
    

}

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

int main() {
    int n, t, a;
    cin >> n >> t >> a;
    vector<int> h(n);
    REP(i, n) cin >> h[i];
    double eps = 10000;
    int ans = -1;
    REP(i, n) {
        double temp = t - h[i] * 0.006;
        if(abs(temp - a) < eps) {
            eps = abs(temp - a);
            ans = i + 1;
        }
    }
    cout << ans << endl;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputData = Console.ReadLine().Split(' ');
            Int64 allCnt = Int64.Parse(inputData[0]);
            Int64 b = Int64.Parse(inputData[1]);
            Int64 a = Int64.Parse(inputData[2]);

            Int64 count = allCnt / (a + b);
            Int64 per = allCnt % (a + b);
            Int64 bcnt = 0;
            if (per == 0)
            {

            }
            else if (per <= b)
            {
                bcnt = per;
            }
            else {
                bcnt = b;
            }


            Console.WriteLine(count * b + bcnt );
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
int main(void) { int H, W; int i, j; for(; ; ) { scanf("%d%d", &H, &W); if(H==0 && W==0) break; for(j=0; j<W; j++) { putchar('#'); } putchar('\n'); for(i=0; i<H-2; i++) { putchar('#'); for(j=0; j<W-2; j++) { putchar('.'); } putchar('#'); putchar('\n'); } for(j=0; j<W; j++) { putchar('#'); } putchar('\n'); putchar('\n'); } return 0; } 





Measured memory_bytes: 2516
# abc 158
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

S = readline().strip().decode('utf-8')
Q = int(readline())

is_reversed = False

import collections
answer = collections.deque(S)
for _ in range(Q):
    l = readline().decode('utf-8').split()
    if len(l) == 1:
        is_reversed = not is_reversed
    else:
        _, F, C = map(str, l)
        if F == "1":
            if is_reversed:
                answer.append(C)
            else:
                answer.appendleft(C)
        else:
            if is_reversed:
                answer.appendleft(C)
            else:
                answer.append(C)

if is_reversed:
    answer.reverse()
print("".join(answer))

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

int main() {
	int n,x; cin>>n>>x;
	vector<int> a(n);
	for (int i=0; i<n; i++)
		cin>>a[i];
	sort(a.begin(), a.end());
	int ret=0;
	for (int i=0; i<n-1; i++)
		if(x>=a[i])
			x-=a[i], ret++;
	if(x==a[n-1])
		ret++;
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
using ll = long long;
ll a[nax];
ll const inf = 1e18;

int main () {
    int n;
    long long ans = 1, x;

    scanf("%d", &n);

    for (int i = 1 ; i <= n ; ++ i)
        scanf("%lld", a + i);

    sort(a + 1, a + 1 + n);

    for (int i = 1 ; i <= n ; ++ i) {
        if (a[i] == 0) return !printf("0");
        if (inf / a[i] < ans) {
            return !printf("-1");
        }

        ans *= a[i];
        if (ans > inf) return !printf("-1");
    }
    printf("%lld\n", ans);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 4612
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std ;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int a,b,c;
long long k;

int main()
{
    while(~scanf("%d%d%d%lld",&a,&b,&c,&k))
    {
        printf("%d\n",k%2==0?a-b:b-a);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
int p[100005], q[100005], r[100005];

int main(void)
{
	ll ans = 0;
	int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
	for(int i=1;i<=a;i++) scanf("%d", &p[i]);
	for(int i=1;i<=b;i++) scanf("%d", &q[i]);
	for(int i=1;i<=c;i++) scanf("%d", &r[i]);
	sort(p+1, p+a+1, [](int x, int y){return x>y;});
	sort(q+1, q+b+1, [](int x, int y){return x>y;});
	sort(r+1, r+c+1, [](int x, int y){return x>y;});
	priority_queue<int> color;
	priority_queue<int> no_color;
	for(int i=1;i<=x;i++) color.push(-p[i]);
	for(int i=1;i<=y;i++) color.push(-q[i]);
	for(int i=1;i<=c;i++) no_color.push(r[i]);
	while(!no_color.empty()){
		int top = no_color.top();
		if(top <= -color.top()) break;
		ans += top;
		no_color.pop();
		color.pop();
	}
	while(!color.empty()) {
		ans -= color.top();
		color.pop();
	}
	cout << ans << endl;
	return 0;
}


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

namespace ABC089D2 {
    class Program {
        static void Main(string[] args) {
            int[] HWDInput = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int H = HWDInput[0];
            int W = HWDInput[1];
            int D = HWDInput[2];
            int[] xpos = new int[H * W];
            int[] ypos = new int[H * W];
            int[,] alldis = new int[D, (H * W + D - 1) / D];
            for (int i = 0; i < H; i++) {
                int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                for (int j = 0; j < W; j++) {
                    int n = input[j] - 1;
                    xpos[n] = i;
                    ypos[n] = j;
                }
            }
            for (int i = 0; i < D; i++) {
                for (int j = 0; j < (H * W + D - 1) / D; j++) {
                    if(j == 0) {
                        alldis[i, j] = 0;
                    } else {
                        int num = i + j * D;
                        if(num < H * W) {
                            int xdis = Math.Abs(xpos[num] - xpos[num - D]);
                            int ydis = Math.Abs(ypos[num] - ypos[num - D]);
                            alldis[i, j] = alldis[i, j - 1] + xdis + ydis;
                        }
                    }
                }
            }
            int Q = int.Parse(Console.ReadLine());
            for (int i = 0; i < Q; i++) {
                int[] LRInput = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                int L = LRInput[0] - 1;
                int R = LRInput[1] - 1;
                int Li = L % D;
                int Lj = L / D;
                int Rj = R / D;
                Console.WriteLine(alldis[Li , Rj] - alldis[Li , Lj]);
            }
        }
    }
}


Measured memory_bytes: 17836
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	cin >> n;
	ll cnt = 0;
	vector<vector<char>> str(n);
	vector<string> ss(n);
	vector<ll> cc(n);
	rep(i, n) {
		ss[i] = "";
		cc[i] = 1;
		str[i].resize(10);
		rep(j, 10) {
			cin >> str[i][j];
		}
		sort(str[i].begin(), str[i].end());
		rep(j, 10) {
			ss[i] += str[i][j];
		}
	}
	sort(ss.begin(), ss.end());
	string flg = ss[0];
	ll j = 0;
	for (ll i = 1; i < n; i++) {
		if (ss[i] == flg) {
			cc[j]++;
		}
		else {
			flg = ss[i];
			j++;
		}
	}
	rep(i, j + 1) {
		cnt += (cc[i] * (cc[i] - 1) / 2);
	}
	
	cout << cnt << endl;
}



Measured memory_bytes: 14048
N,K,Q = map(int,input().split())
A = []
lst_2 = [0] * N
for i in range(Q):
    A.append(int(input()))
for i in range(Q):
    p = A[i]
    lst_2[p-1] += 1
for i in range(N):
    if lst_2[i] > -K+Q:
        print("Yes")
    else:
        print("No")

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

using namespace std;

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 += __gcd(a, __gcd(b, c));
            }
        }
    }
    cout << ans << endl;
}


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

void solve()
{
	int n, x;
	cin >> n >> x;
	vector<int> m(n);
	for(auto&& i : m)
	{
		cin >> i;
	}
	sort(begin(m), end(m));
	cout << n + (x - accumulate(begin(m), end(m), 0)) / m[0] << "\n";
}

int main()
{
	solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200010],b[200010];
signed main(){
	long long n;
	cin>>n;
	for(long long i=1;i<=n;++i) cin>>a[i]>>b[i];
	sort(a+1,a+1+n);
	sort(b+1,b+1+n);
	if(n&1) cout<<(b[n/2+1]-a[n/2+1]+1);
	else cout<<(b[n/2]+b[n/2+1]-a[n/2]-a[n/2+1]+1);
	return 0;
}

Measured memory_bytes: 5188
import scala.io.StdIn.{readInt,readLine}

object Main extends App {
  val n = readInt
  for(i<- 0 until n) {
    var s = readLine
    for(j<-0 until s.length-6) {
      if(s.substring(j,j+7) == "Hoshino")
        s = s.updated(j+6,'a')
    }
    println(s)
  }
}

Measured memory_bytes: 45460
//图的直径默认为，两点间最短距离最长的那个
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 205;
const int inf = maxn + 5;

char s[maxn];
int gr[maxn][maxn];
int d[maxn];
queue<int> q;
int n;
int answer = 0;

void go(int start)
{
	for (int i = 0; i < n; i++) d[i] = inf;
	d[start] = 0;
	q.push(start);
	while (!q.empty())
	{
		int cur = q.front();
		//cout<<start<<" "<<cur<<" "<<d[cur]<<endl;
		q.pop();
		answer = max(answer, d[cur] + 1);
		for (int i =0 ; i < n; i++) if (gr[cur][i] && d[i] > d[cur] + 1)
		{
			d[i] = d[cur] + 1;
			q.push(i);
		}
	}
	if (start == 0)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++) if (gr[i][j] && d[i] == d[j])
			{
				cout << -1 << endl;
				exit(0);
			}
		}
	}
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%s", s);
		for (int j = 0; j < n; j++) gr[i][j] = s[j] - '0';
	}
	answer = 0;
	for (int i = 0; i < n; i++) go(i);
	cout << answer << endl;
    return 0;
}


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

N,K=map(int,input().split())
ANS=[]

x=N-2
if (x+1)*x//2<K:
    print(-1)
    sys.exit()

for i in range(2,N+1):
    ANS.append((1,i))

NOW=2
while True:
    
    if K<=N-NOW:
        for i in range(NOW+1,N-K+1):
            ANS.append((NOW,i))

        for i in range(NOW+1,N):
            for j in range(i+1,N+1):
                ANS.append((i,j))

        break

    else:
        K-=(N-NOW)
        NOW+=1

ANS=list(set(ANS))
print(len(ANS))
for ans in ANS:
    print(*ans)
    



Measured memory_bytes: 45040
#include<iostream>
using namespace std;
int main(){
    int a,b,c,i;
    int count=0;
    cin>>a >>b >>c;
    for(i=a;i<=b;i++){
        if(c%i==0){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}



Measured memory_bytes: 3100
// https://atcoder.jp/contests/abc100/tasks/abc100_c

#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, sum = 0;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> m;
        // 2で割れる回数の合計を計算する
        int div = 1;
        while (m % (1 << div) == 0) {
            div++;
        }
        sum += (div - 1);
    }

    cout << sum << endl;

    return 0;
}


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

int main(){

  long long x,ans;
  cin >> x;

  ans = x/11;
  ans = 2*(ans) + ((x-ans*11)>6 ? 2 : x%11 ? 1 : 0);
  cout << ans << endl;

  return 0;
}


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

long modperm(long n, long r, long d) {
	return 
		r == 0 ? 1:
		n * modperm(n - 1, r - 1, d) % d;
}

long modpow(long a, long p, long d) {
	return
		p == 1 ? a % d :
		p % 2 == 0 ? modpow(a, p / 2, d) * modpow(a, p / 2, d) % d :
		modpow(a, p - 1, d) * a % d;
}

int main() {
  long n, a, b;
  cin >> n >> a >> b;
  long d = 1e9 + 7;
  
  long N = modpow(2, n, d) - 1;
  long A = modperm(n, a, d) * modpow(modperm(a, a ,d), d - 2, d) % d;
  long B = modperm(n, b, d) * modpow(modperm(b, b ,d), d - 2, d) % d;
  cout << (N - A - B + d * 2) % d << endl;
  return 0;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

/*
 * Union-Find tree
 * header requirement: vector
 */
class UnionFind {
private:
  std::vector<int> disj;
  std::vector<int> rank;
public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
	++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) {
    return root(x) == root(y);
  }
};


int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  VI p(n);
  REP(i, 0, n) {
    cin >> p[i];
    p[i]--;
  }
  UnionFind uf(n);
  REP(i, 0, m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    uf.unite(x, y);
  }
  vector<VI> pool(n), matched(n);
  REP(i, 0, n) {
    int r = uf.root(i);
    pool[r].push_back(i);
    matched[r].push_back(p[i]);
  }
  int tot = 0;
  REP(i, 0, n) {
    set<int> pset(pool[i].begin(), pool[i].end());
    REP(j, 0, matched[i].size()) {
      int w = matched[i][j];
      if (pset.count(w)) tot++;
    }
  }
  cout << tot << endl;
}


Measured memory_bytes: 12416