akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

//#include<boost/circular_buffer.hpp>
using namespace std;

//cout << fixed << setprecision(10);
typedef long long ll;
#define PI 3.141592653589793
#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}
	long long int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

long long int lcm(long long int a, long long int b) {
	long long int L;
	L = a / gcd(a, b);
	L *= b;
	return L;
}

vector<long long  int> Prime;
void Eratosthenes(long long int n) {
	vector<bool> is_prime(n, true);
	is_prime.at(0) = false;
	is_prime.at(1) = false;
	for (long long int i = 2; i * i <= n; i++) {
		if (is_prime.at(i)) {
			for (int j = i * i; j < n; j += i) {
				is_prime.at(j) = false;
			}
		}
	}
	for (int i = 2; i < n; i++) {
		if (is_prime.at(i))
			Prime.emplace_back(i);
	}
}

/*
map<int, int> prime;
void Prime_number(long long int n) {
	for (int i = 2; i <= n; i++) {
		int count = 0;
		while (n % i == 0) {
			count++;
			n /= i;
		}
		if (count != 0) {
			prime.insert(make_pair(i, count));
		}
	}
}
*/
//std::cout.fill('0');

int keta(long long int N) {
	int k = 0;
	while (N > 0) {
		N /= 10;
		k++;
	}
	return k;
}

int Combination(int n, int m) {
	long long int s = 1, t = 1;
	int tmp = n;
	while (n - m != tmp) {
		s *= tmp;
		tmp--;
	}
	tmp = m;
	while (tmp != 1) {
		t *= tmp;
		tmp--;
	}
	return s / t;
}


int main() {
	long long n;
	char s;
	cin >> s;
	s += 1;
	cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//freopen("transmitters.in","r",stdin);
//cout<<fixed<<setprecision(6)<<n<<endl;
// transform(s.begin(), s.end(), s.begin(), ::tolower);
//double PI=3.14159265359,c=0;
#define all(v) v.begin(),v.end()
#define endl '\n'
#define ll long long
//#define f(n) for(int i=;i<n;i++)
double PI = acos(-1);
using namespace std;
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int arr[1000005], n;
vector<int>v(1e5+2, -1);
int minCost(int indx)
{
	int path1=INT_MAX, path2=INT_MAX;
	if (indx == n - 1)
		return 0;

	if (v[indx] != -1)
		return v[indx];

	if (indx + 1 < n)
		path1 = abs(arr[indx] - arr[indx + 1]) + minCost(indx + 1);

	if (indx + 2 < n)
		path2 = abs(arr[indx] - arr[indx + 2]) + minCost(indx + 2);

	return v[indx] = min(path1, path2);
}
int main()
{
	fast();
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	cout << minCost(0) << endl;

	return 0;
}

Measured memory_bytes: 4224
N = int(input())

n15 = N // 15
n3 = N // 3
n5 = N // 5

sum15 = n15*(n15+1)//2 * 15
sum3 = n3*(n3+1)//2 * 3
sum5 = n5*(n5+1)//2 * 5

ans = N*(N+1)//2 + sum15 - sum3 - sum5
print(int(ans))

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

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

int main(){
  ll N,A,B,C,D,E;
  cin>>N>>A>>B>>C>>D>>E;
  if(N%min({A,B,C,D,E})!=0)
  cout<<N/min({A,B,C,D,E})+5<<endl;
  else
    cout<<N/min({A,B,C,D,E})+4<<endl;



  return 0;
}
  


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;
int main(){
    int x[3];
    for(int i ;i<3;i++){
        cin>>x[i];
    }
    sort(x,x+3);
    cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<endl;
    
}


Measured memory_bytes: 3156
package main

import "fmt"

func contains(a []int,b int)bool{
	for _,value := range a{
		if value == b{
			return true
		}
	}
	return false
}

func dfs(grid [][]int,visited []int,now int,count *int){
	copy_visited := append([]int{},visited...)
	copy_visited = append(copy_visited,now)
	if len(copy_visited) == len(grid){
		*count++
		return
	}
	for idx,value := range grid[now] {
		if value == 1 && !contains(copy_visited,idx){
			dfs(grid,copy_visited,idx,count)
		}
	}
}

func main(){
	var node,edge,to,from int
	fmt.Scan(&node,&edge)
	grid := make([][]int,node)
	for i :=0;i < node ;i++{
		grid[i] = make([]int,node)
	}
	for i:=0;i<edge;i++{
		fmt.Scan(&to,&from)
		grid[to-1][from-1] = 1
		grid[from-1][to-1] = 1
	}
	count := 0
	dfs(grid,[]int{},0,&count)
	fmt.Println(count)
}



Measured memory_bytes: 1792
# from scipy.misc import comb
# from scipy.special import comb
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def banned(al):
    d = {}
    for a in al:
        if a in d.keys():
            d[a] += 1
        else:
            d[a] = 1
    # print(d)
    ans = 0
    for k, v in d.items():
        if v > 1:
            ans += comb(v, 2)
            # d[k] = [v, comb(v, 2)]
        # else:
            # d[k] = [v, 0]
    # print(ans)
    for a in al:
        # for k, v in d.items():
        #     if k == a:
        #         if v[0] > 2:
        #             ans += comb(v[0]-1, 2)
        #     else:
        #         ans += v[1]
        print(int(ans-(d[a]-1)))

n = int(input())
al = [int(i) for i in input().split()]

banned(al)

Measured memory_bytes: 26268
#include <bits/stdc++.h>
using namespace std;
long long n,p,arr[100001],fact[100001],tot,dp[100001];
long long power(long long x,long long y){
    long long res=1;
    x%=p;
    while (y>0){
        if (y%2==1) res=(res*x)%p;
        y/=2;
        x=(x*x)%p;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>arr[i];
    }
    p=1e9+7;
    fact[0]=1;
    for (int i=1;i<=n;i++){
        fact[i]=(fact[i-1]*i)%p;
        dp[i]=dp[i-1]+power(i,p-2);
    }
    for (int i=1;i<n;i++){
        long long cur=dp[i];
        tot+=cur*(arr[i+1]-arr[i]);
        tot%=p;
    }
    tot*=fact[n-1];
    tot%=p;
    cout<<tot;
}

Measured memory_bytes: 2560
import java.util.*;
import java.math.BigInteger;
import static java.lang.System.*;
import java.util.*;
import java.math.BigInteger;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int count = 0;
		if (N > 1) {
			count += (N * (N-1)) / 2;
		}
		if(M > 1) {
			count += (M * (M-1))/ 2;
		}
		out.print(count);
;
	}
}


Measured memory_bytes: 23508
import java.util.*;
 
public class Main {
  public static void main(final String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    
    int ans = 0;
    ans = (int) Math.pow(K-1,N-1);
    System.out.println(ans*K);
  }
}

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

int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    ll total=(ll)pow(2,n+2)-3;
    //cout<<total;
    for (ll i = n; i >= 0; --i) {
        if(k>=(total+1)/2){
            ans+=(ll)pow(2,i);
            k-=(total+1)/2;
        }
        else{
            k-=1;
        }
        total=(total-3)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String s = scan.next();
        System.out.print(s.charAt(0));
        System.out.print(s.length() - 2);
        System.out.println(s.charAt(s.length()-1));
    }
}

Measured memory_bytes: 22868
package main

import (
	"fmt"
)

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	nCi := pow(2, n) - 1
	nCa := comb(n, a)
	nCb := comb(n, b)

	ans := sub(nCi, add(nCa, nCb))
	fmt.Println(ans)
}

const mod int = 1e9 + 7

func pow(n, k int) int {
	if k == 0 {
		return 1
	} else if k%2 == 1 {
		return pow(n, k-1) * n % mod
	} else {
		t := pow(n, k/2)
		return t * t % mod
	}
}

func comb(n, r int) int {
	nu := 1
	for i := 0; i < r; i++ {
		nu = mul(nu, n-i)
	}

	de := 1
	for i := 1; i <= r; i++ {
		de = mul(de, i)
	}

	return div(nu, de)
}

func add(a, b int) int {
	return (a + b) % mod
}

func sub(a, b int) int {
	return (a + mod - b) % mod
}

func mul(a, b int) int {
	return a % mod * b % mod % mod
}

func div(a, b int) int {
	return mul(a, pow(b, mod-2))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    if(n%2 == 0) cout << n << endl;
    else cout << n*2 << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <algorithm>
using namespace std;

int n;

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')c=getchar(),t=-1;
	while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+(c^48),c=getchar();
	return s*t; 
}

int main(void){
	n=read();
	for(int i=1;i<=n;i++){
		int a=read();
		if(a%2!=0)continue;
		if(a%3==0||a%5==0)continue;
		printf("DENIED\n");
		return 0;
	}
	printf("APPROVED\n");
}

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


long long int A[200000] = {};
long long int ans[200000] = {};

int main() {
	int N;
	cin >> N;
	
	long long int sum = 0;
	
	for(int i = 1; i <= N; i++){
		cin >> A[i];
		sum += abs(A[i] - A[i - 1]);
	}
	
	sum += abs(A[N]);
	
	for(int i = 1; i < N; i++){
		cout << sum - abs(A[i] - A[i - 1]) - abs(A[i] - A[i + 1]) + abs(A[i + 1] - A[i - 1]) << endl;
	}
	
	cout << sum - abs(A[N] - A[N - 1]) - abs(A[N] - A[0]) + abs(A[0] - A[N - 1]) << endl;
	
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	long n;
	cin >> n;
	vector<string> s(n);
	for (long i = 0; i < n; ++i) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}

	sort(s.begin(), s.end());
	long ans = 0;
	long same = 0;

	string now = s[0];
	for (long i = 1; i < n; ++i) {
		if (s[i] == now) {
			++same;
		} else {
			//--same;
			ans += same * (same + 1) / 2;
			same = 0;
			now = s[i];
		}
	}
	if (same != 0) {
		//--same;
		ans += same * (same + 1) / 2;
	}

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

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

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

long long lcm(long long a, long long b)
{
    long long temp = gcd(a, b);

    return temp ? (a / temp * b) : 0;
}


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

    int cnt = 1;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == cnt) {
            cnt++;
        }
        else {
            ans++;
        }
    }

    if (cnt == 1) {
        cout << -1 << endl;
    }
    else {
        cout <<ans<< endl;
    }
    return 0;
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using i64 = long long;

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

    for (int i = 1; i <= 10000; i++) {
        if ((int)(i * 0.08) == a && (int)(i * 0.10) == b) {
            std::cout << i << std::endl;
            return 0;
        }
    }

    std::cout << -1 << std::endl;

    return 0;
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

typedef long long ll;
typedef pair<int,int> p;

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

string s;
int x, y, N;
int main(){
    ios::sync_with_stdio(false);
    cin >> s;
    cin >> x >> y;
    N = s.length();
    vector<int> vx;
    vector<int> vy;
    
    int countF = 0;
    int countT = 0;
    REP(i, N) {
        if (s[i] == 'F') {
            countF++;
        } else {
            if (countT % 2 == 0) {
                vx.pb(countF);
            } else {
                vy.pb(countF);
            }
            countT++;
            countF = 0;
        }
    }
    if (countF > 0) {
        if (countT % 2 == 0) {
            vx.pb(countF);
        } else {
            vy.pb(countF);
        }
    }
    
    vector<vector<bool> > xdp(vx.size() + 1, vector<bool>(N*2+1, 0));
    vector<vector<bool> > ydp(vy.size() + 1, vector<bool>(N*2+1, 0));
    
    int add = 0;
    if (s[0] == 'T') {
        xdp[0][N] = true;
    } else {
        xdp[1][N + vx[0]] = true;
        add++;
    }
    FOR(i, add, vx.size()) {
        REP(j, xdp[0].size()) {
            if (!xdp[i][j]) continue;
            xdp[i+1][j-vx[i]] = xdp[i][j];
            xdp[i+1][j+vx[i]] = xdp[i][j];
        }
    }
    
    ydp[0][N] = true;
    REP(i, vy.size()) {
        REP(j, ydp[0].size()) {
            if (!ydp[i][j]) continue;
            ydp[i+1][j-vy[i]] = ydp[i][j];
            ydp[i+1][j+vy[i]] = ydp[i][j];
        }
    }
    
    if (ydp[vy.size()][N+y] && xdp[vx.size()][N+x]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


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

const int MAXN = 100010;
int h[MAXN], dp[MAXN];
int n;

int calc(int pos) {
    if(pos == n) return 0;
    int &y = dp[pos];
    if(y != -1) return y;
    y = calc(pos+1) + abs(h[pos] - h[pos+1]);
    if(pos+1 != n) y = min(y, calc(pos+2) + abs(h[pos] - h[pos+2]));
    return y;
}

int main() {
    memset(dp, -1, sizeof(dp));
	cin >> n;
	for(int i=1; i<=n; ++i) {
	    cin >> h[i];
	}
	cout<<calc(1)<<endl;
	return 0;
}


Measured memory_bytes: 8956
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		int[] bingo = new int[9];
      	for(int i = 0;i<9;i++){
			bingo[i] = scn.nextInt();
        }
		int n = scn.nextInt();
      	for(int j = 0; j < n;j++){
            int x = scn.nextInt();
          	for(int k = 0; k<9;k++){
              if( x == bingo[k]){
               		 bingo[k] = 0;
              }
            }
        }
      	String ret = "No";
      	int[][] places = {{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}};
      	for(int l = 0;l<8;l++){
          int[] place = places[l];
          if(bingo[place[0]]+bingo[place[1]]+bingo[place[2]] == 0){
            ret = "Yes";
          }
        }
      	System.out.println(ret);
	}
}

Measured memory_bytes: 23892
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    char a ,b;
    cin >> a >> b;
    if( a == 'H' && b == 'H') cout << 'H' << endl;
    else if( a == 'D' && b == 'H') cout << 'D' << endl;
    else if( a == 'D' && b == 'D') cout << 'H' << endl;
    else  cout << 'D' << endl;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
H = list(map(int,input().split()))

way = [set([]) for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    way[a-1].add(b-1)
    way[b-1].add(a-1)

height = [[] for _ in range(N)]
for i in range(N):
    for tower in way[i]:
        height[i].append(H[tower])

ans = 0
for i in range(N):
    if len(way[i]) == 0:
        ans += 1
        #print(i)
        continue
    if H[i] > max(height[i]):
        ans += 1
        #print("H[i]=",H[i],"max=",max(height[i]))
        #print(i)
        
print(ans)

Measured memory_bytes: 55428
def taro_turn(ba):
    if ba==0:
        return(taro.pop(-1))
    elif ba>0:
        for i in range(len(taro))[::-1]:
            if taro[i]>ba:
                k=taro[i]
                taro.remove(k)
                return(k)
        return(0)
def hana_turn(ba):
    if ba==0:
        return(hana.pop(-1))
    elif ba>0:
        for i in range(len(hana))[::-1]:
            if hana[i]>ba:
                k=hana[i]
                hana.remove(k)
                return(k)
        return(0)
    
while 1:
    n=int(input())
    if n==0:break
    taro=[]
    hana=[]
    tarop=0
    hanap=0
    for i in range(n):
        taro.append(int(input()))
    for i in range(1,2*n+1)[::-1]:
        if not i in taro:
            hana.append(i)
    taro.sort(reverse=True)
    ba=0
    while 1:
        ba=taro_turn(ba)
        if len(taro)==0:
            tarop+=len(hana)
            break
        ba=hana_turn(ba)
        if len(hana)==0:
            hanap+=len(taro)
            break
    print(tarop)
    print(hanap)


Measured memory_bytes: 5600
from functools import reduce
from fractions import gcd
from math import ceil

N, M = map(int, input().split())
A = list(map(int, input().split()))

def lcm(a, b):
    return a * b // gcd(a, b)

def bit(a):
    res = 0
    _a = a
    while _a % 2 == 0:
        _a /= 2
        res += 1
    return res

count = bit(A[0])
for i in range(1, len(A)):
    if bit(A[i]) != count:
        print(0)
        exit()
half_A = [ a // 2 for a in A]

min_X = half_A[0]
for a in half_A:
    min_X = lcm(a, min_X)
    if min_X > M:
        print(0)
        exit()

res = M // min_X

print(int((res+1)//2))


Measured memory_bytes: 16288
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n,m;
  cin>>n>>m;
  map<long long int,long long int> hoge;
  vector<long long int> a(n);
  queue<long long int> all;
  long long int ans=0;
  for(long long int i=0; i<n; i++){
    cin>>a.at(i);
    ans+=a.at(i);
  }
  vector<pair<long long int,long long int>> b(m);
  for(long long int i=0; i<m; i++){
    cin>>b.at(i).second>>b.at(i).first;
  }

  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());

  for(long long int i=0; i<n; i++){
    if(i==0){
      hoge[a.at(i)]++;
      all.push(a.at(i));
    }else{
      hoge[a.at(i)]++;
      if(a.at(i)!=a.at(i-1)){
        all.push(a.at(i));
      }
    }
  }


  for(long long int i=0; i<m; i++){
    if(all.size()<=0){
      break;
    }
    while(true){
      if(all.size()<=0){
        break;
      }
      long long int low=all.front();
      if(b.at(i).first<=low){
        break;
      }
      if(b.at(i).second>=hoge[low]){
        ans-=hoge[low]*low;
        ans+=hoge[low]*b.at(i).first;
        b.at(i).second-=hoge[low];
        hoge[b.at(i).first]=hoge[low];
        hoge[low]=0;
      }else{
        ans-=low*b.at(i).second;
        ans+=b.at(i).first*b.at(i).second;
        hoge[low]-=b.at(i).second;
        hoge[b.at(i).first]+=b.at(i).second;
        b.at(i).second=0;
      }

      if(b.at(i).second<=0){
        break;
      }
      if(hoge[low]==0){
        all.pop();
      }
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 101, K = 1e5 + 5;

int n, k;
int memo[K], arr[N];

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

	cin >> n >> k;
	rep(i, 0, n)
		cin >> arr[i];

	erep(i, 1, k)
	{
		int cnt = 0;
		rep(j, 0, n)
		{
			if (i - arr[j] < 0)
			{
				cnt++;
				continue;
			}
			if (memo[i - arr[j]])
				cnt++;
		}
		if (cnt != n)
			memo[i] = 1;

//		cout << memo[i] << " ";
	}
//	cout << endl;

	if (memo[k])
		cout << "First";
	else
		cout << "Second";

	return 0;
}


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

int main(void){

    int N,M; cin>>N>>M;
    vector<int> X(M);
    for (int i = 0; i < M; ++i) {
        cin>>X[i];
    }
    sort(X.begin(), X.end());

    //距離の配列
    vector<int> kyori(M-1);
    for (int i = 0; i < M-1; ++i) {
        kyori[i] = X[i+1] - X[i];
    }
    sort(kyori.begin(), kyori.end());
    int ans=0;
    for (int i=0; i<M-N; i++) {
        ans+=kyori[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int n;
  stack<int> stk;
  while (cin >> n) {
    if (n) {
      stk.push(n);
    } else {
      cout << stk.top() << "\n";
      stk.pop();
    }
  }
  return 0;
}


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

namespace AtCoder_ABC_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var heightList = new List<int>();
            int ans = 0;

            String[] inputLineNK = Console.ReadLine().Split(' ');
            int n = int.Parse(inputLineNK[0]);
            int k = int.Parse(inputLineNK[1]);

            String[] inputLineHeights = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                heightList.Add(int.Parse(inputLineHeights[i]));
            }

            for (int i = 0; i < n; i++)
            {
                if(heightList[i] >= k)
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 16224
#include<iostream>
using namespace std;
int main()
{
    int n,m,d;
    cin>>n>>m>>d;
    if(d==0)
    {
        double a=(n-d);
        double b=a/n;
        b*=(m-1);
        double ans=b/n;
        cout.setf(ios::fixed);
        cout.precision(10);
        cout<<ans<<endl;
        return 0;
    }
    else
    {
        double a=(n-d);
        double b=a/n;
        b*=(m-1);
        double ans=b/n;
        ans*=2;
        cout.setf(ios::fixed);
        cout.precision(10);
        cout<<ans<<endl;
        return 0;
    }
}

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


#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;


using namespace std;

const double pi = 3.141592654;

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

    int r;
    cin >> r;
    cout << 2*pi*r;
    return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s,t; cin>>s>>t;
  if(s.size()<=10 && t.substr(0,t.size()-1)==s) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3656
import java.util.*;

class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int w = Integer.parseInt(sc.next());
		int h = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int y = Integer.parseInt(sc.next());
		
		if(w % 2 == 0 && w / 2 == x && h % 2== 0 && h / 2 == y) {
		    System.out.println(Double.toString((double)w * (double)h / 2.0) + ' ' + '1');
		}
		else {
		    System.out.println(Double.toString((double)w * (double)h / 2.0) + ' ' + '0');
        }
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e6+10;
int n,cnt[3];
char s[N];

inline int C(int n,int m){
	if (n<m) return 0;
	if (n<=1) return 1; 
	return C(n/2,m/2)*C(n%2,m%2)%2;
}

int main(){
	n=read()-1,scanf("%s",s+1);
	For(i,1,n) s[i]=abs(s[i]-s[i+1]);
	if (n==1) return printf("%d\n",s[1]),0; 
	For(i,1,n) cnt[s[i]]++;
	if (cnt[1]==0){
		int ans=0;
		For(i,1,n) if (s[i]) ans=(ans+C(n-1,i-1))%2;
		printf("%d\n",ans==1?2:0);
	} else {
		int ans=0;
		For(i,1,n) if (s[i]==1) ans=(ans+C(n-1,i-1))%2;
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 4800
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int h, w;
char field[10][10];


signed main(){
	scanf("%ld %ld", &h, &w);
	for(int i = 0; i < h; i++){
		scanf("%s", field[i]);
	}
	for(int i = 0; i < h + w - 1; i++){
		int cnt = 0;
		for(int j = 0; j <= i; j++){
			if(i-j < w && field[j][i-j] == '#'){
				cnt++;
			}
		}
		//printf("%ld %ld\n", i, cnt);
		if(cnt != 1){
			printf("Impossible\n");
			return 0;
		}
	}
	printf("Possible\n");
	return 0;
}


Measured memory_bytes: 256
ProNum = int(input())
time = input()
time = (time.split())
TotalTime = 0

for t in time:
  TotalTime += int(t)
                  
DrinkNum = int(input())

for d in range(DrinkNum):
  line = input()
  line = line.split()
  diff = int(line[1]) - int(time[int(line[0])-1])
  print(TotalTime+diff)

Measured memory_bytes: 9052
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n;cin>>n;
    vector<ll> v(n);
    REP(i,n)cin>>v[i];
    ll a=1, l;
    REP(i,n) l=lcm(a,v[i]),a=l;
    cout<<l;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 3e5 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 8e17 + 51;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

int a[N], b[N];

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && c != a && c != b) {
        cout << "Yes";
        return 0;
    }
    if (a == c && b != a && b != c) {
        cout << "Yes";
        return 0;
    }
    if (b == c && a != b) {
        cout << "Yes";
        return 0;
    }
    cout << "No";
}


Measured memory_bytes: 256
#include<stdio.h>
int min(int a,int b){
	if(a>b)a=b;
	return a;
}
int max(int a,int b){
	if(a<b)a=b;
	return a;
}
int main(){
	int a,b,n,k,m=0,i,j,x[100001],y[100001],z=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n-1;i++)scanf("%d",&x[i]);
	for(i=0;i<k;i++)scanf("%d",&y[i]);
	for(i=0;i<k;i++){
		a=min(m,m+y[i]),b=max(m,m+y[i]);
		for(j=a;j<b;j++)z+=x[j];
		m+=y[i];
		z%=100000;
	}
	printf("%d\n",z);
	return 0;
}


Measured memory_bytes: 2636
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
#define DEBUG

typedef struct node{
  struct node* parent;
  struct node* left;
  struct node* right;
  int k;
}Node;

Node* tree;

void insert(int);
void inorder(Node*);
void preorder(Node*);
void delete(Node*);
Node* find(Node*,int);
Node* Minimum(Node*);
Node* Successor(Node*);

int main(){
  int m,i,k;
  char s[10];
  Node* f;

  scanf("%d",&m);

  for(i=0;i<m;i++){
    scanf("%s",s);
    if(s[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    else if(s[0]=='p'){
      inorder(tree);
      printf("\n");
      preorder(tree);
      printf("\n");
    }
    else if(s[0]=='f'){
      scanf("%d",&k);
      f=find(tree,k);
      if(f!=NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(s[0]=='d'){
      scanf("%d",&k);
      if((f=find(tree,k))!=NIL) delete(f);
    }
  }

  return 0;
}

void insert(int k){
  Node* y = NIL;
  Node* x = tree;
  Node* z;
  z=(Node *)malloc(sizeof(Node));
  z->k=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->k < x->k ){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y==NIL) tree=z;
  else if(z->k < y->k) y->left=z;
  else y->right=z;
  return;
}

void inorder(Node* tree){
  if(tree != NIL){
    inorder(tree->left);
    printf(" %d",tree->k);
    inorder(tree->right);
  }
  return;
}

void preorder(Node* tree){
  if(tree != NIL){
    printf(" %d",tree->k);
    preorder(tree->left);
    preorder(tree->right);
  }
  return;
}

Node* find(Node* tree,int f){
  if(tree != NIL){
    if(tree->k == f) return tree;
    if(tree->k > f) return find(tree->left,f);
    else return find(tree->right,f);
  }
  else return NIL;
}

void delete(Node* z){
  Node* y;
  Node* x;

  if(z->left == NIL || z->right == NIL) y=z;
  else y=Successor(z);

  if(y->left!=NIL) x = y->left;
  else x=y->right;
  if(x!=NIL) x->parent = y->parent;

  if(y->parent==NIL) tree=x;
  else if(y==y->parent->left) y->parent->left=x;
  else y->parent->right = x;

  if(y!=z){
    z->k = y->k;
  }

  return;
}

Node* Minimum(Node* x){
  while(x->left != NIL){
    x=x->left;
  }
  return x;
}

Node* Successor(Node* x){
  Node* y;

  if(x->right != NIL) return Minimum(x->right);

  y = x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

Measured memory_bytes: 19364
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int totalSum = 0;

int main()
{
	int n;
	cin >> n;
	string S[50];
	int M[50][26];

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 26; j++)
		{
			M[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++)
	{
		cin >> S[i];
		for (int j = 0; j < S[i].size(); j++)
		{
			M[i][S[i][j] - 'a']++;
		}
	}

	string T;
	int max = 1000000;

	for (int j = 0; j < 26; j++)
	{
		int minValue = max;
		bool next = false;
		for (int i = 0; i < n; i++)
		{
			if (M[i][j] == 0)
			{
				next = true;
				break;
			}
			minValue = min(minValue, M[i][j]);
		}

		if (!next)
		{
			for (int i = 0; i < minValue; i++)
			{
				T.push_back(j + 'a');
			}
		}
	}

	cout << T << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}
	result := 0
	for i := 0; i < n; i++ {
		if v[i] > c[i] {
			result += (v[i] - c[i])
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef int lli;
lli n, k, a[1009], b[1009], kq=0;
struct T
{
	lli x, y;
	char col;
};
vector<T> v;
void Inp()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		lli x, y;
		char col;
		cin>>x>>y>>col;
		v.push_back({x, y, col});
	}
}
void Solve()
{
	for(int i=0;i<k;i++)
	{
		fill_n(&a[0], sizeof(a)/sizeof(a[0]), 0);
		fill_n(&b[0], sizeof(b)/sizeof(b[0]), 0);
		for(auto node: v)
		{
			if((((node.y+i)/k)%2)^((node.x/k)%2)==1)
			{
				if(node.col=='B')
				{
					a[k-(node.x%k)]++;
					a[k]--;
					b[0]++;
					b[k-(node.x%k)]--;
				}
				else
				{
					a[0]++;
					a[k-(node.x%k)]--;
					b[k-(node.x%k)]++;
					b[k]--;
				}
			}
			else
			{
				if(node.col=='B')
				{
					a[0]++;
					a[k-(node.x%k)]--;
					b[k-(node.x%k)]++;
					b[k]--;
				}
				else
				{
					a[k-(node.x%k)]++;
					a[k]--;
					b[0]++;
					b[k-(node.x%k)]--;
				}
			}
		}
		kq=max(kq, max(a[0], b[0]));
		for(int j=1;j<k;j++)
		{
			a[j]=a[j-1]+a[j];
			b[j]=b[j-1]+b[j];
			kq=max(kq, max(a[j], b[j]));
		}
	}
	cout<<kq;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("test.inp","r",stdin);
	Inp();
	Solve();
}

Measured memory_bytes: 1912
#include<cstdio>
int A[30];
bool solve(int i,int m)
{
    if(i < 0)
        return m == 0;
    else
        return solve(i-1,m) || solve(i-1,m-A[i]);
}
int main()
{
    int n,q;
    int k;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d",&A[i]);
    scanf("%d",&q);
    for(int i=0; i<q; i++)
    {
        scanf("%d", &k);
        if(solve(n,k))
            printf("yes\n");
        else
            printf("no\n");
    }

    return 0;
}



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

using namespace std;

bool isAll(const std::string &s) {
  char const c = s.front();
  for (char const cc : s) {
    if (cc != c) {
      return false;
    }
  }
  return true;
}

int solve(const std::string &s) {
  if (isAll(s)) {
    return 0;
  }

  int ret = s.size();
  for (char c = 'a'; c <= 'z'; c++) {
    std::vector<char> ss(s.begin(), s.end());
    bool foundAll;
    do {
      foundAll = true;
      for (int i = 0; i < ss.size() - 1; i++) {
        bool const found = ss[i] == c || ss[i + 1] == c;
        if (found) {
          ss[i] = c;
        }
        foundAll = foundAll && found;
      }
      ss.pop_back();
    } while (!foundAll);
    ret = std::min(static_cast<int>(s.size() - ss.size()), ret);
    if (!ret) {
      return ret;
    }
  }
  return ret;
}

int main() {
  std::string s;
  std::cin >> s;
  std::cout << solve(s) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define Iter(c) __typeof__((c).begin())
#define foreach(i,c) for(Iter(c) i = (c).begin();i != (c).end();++i)
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

typedef pair<string,int> SI;

bool ok(string s)
{
  char c = s[0];
  for(int i=0;i<s.length();i++)
    if(c != s[i])
      return false;
  return true;
}

char getc(char c,char cc)
{
  map<char,bool> index;
  index['r'] = false,index['b'] = false,index['g'] = false;
  index[c] = true;
  index[cc] = true;
  foreach(i,index)
    if(!(*i).S)
      return (*i).F;

}

int solve(string s)
{

  queue<SI> que;
  que.push(SI(s,0));
  map<string,bool> used;
  while(!que.empty())
    {
      SI si = que.front(); que.pop();

      if(used[si.F])
	continue;

      used[si.F] = true;
 
      if(ok(si.F))
	{
	  return si.S;
	}

      if(si.S > 20)
	continue;

      rep(i,si.F.length()-1)
	{
	  if(si.F[i] == si.F[i+1])
	    continue;
	  string news = si.F;
	  news[i] = news[i+1] = getc(si.F[i],si.F[i+1]);
	  que.push(SI(news,si.S+1));
	}

    }

  return -1;
}


int main(){

  while(true)
    {
      string s;
      cin >> s;
      if(s[0] == '0')
	break;

      int ans = solve(s);
      ans != -1?cout << ans << endl:cout << "NA" << endl;

    }

return 0;
}

Measured memory_bytes: 3340
s = int (input ())
l = []
a = 0
l.append (s)
for i in range (1000000):
  a += 1
  if s%2 == 0:
    s = round(s/2)
  else:
    s = s*3+1
  if l.count (s) != 0:
    print (a+1)
    break
  else:
    l.append (s)

Measured memory_bytes: 9092
N, K = list(map(int,input().split()))
ans = 0
INF = 10 ** 9 + 7
for i in range(K, N + 2):
    mi = i * (i - 1) // 2
    ma = i * (2 * N - i + 1) // 2
    ans += ma - mi + 1
    ans %= INF
print(ans)

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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

const ll MOD1 = 797208487LL, MOD2 = 919797449LL, EX = 1e9;
struct rolling_hash{
    ll MOD, al, off, i_al = -1;
    vector<ll> ipw, v;
    
    rolling_hash(ll MOD, ll al, ll off): MOD(MOD), al(al), off(off) {}
    
    ll exp(ll a, ll r){
        if(r == 0) return 1;
        ll tmp = exp(a, r/2);
        tmp = (tmp * tmp)%MOD;
        if(r & 1) tmp = (tmp * a)%MOD;
        return tmp;
    }

    void upd(int n){
        if(i_al == -1){
            i_al = exp(al, MOD - 2);
            ipw.pb(1);
        }
        while(sz(ipw) <= n) ipw.pb((ipw.back() * i_al)%MOD);
    }

    template<typename T> void hash(T &str){
        v.assign(sz(str) + 1, 0);
        upd(sz(str) + 5);
        ll nxt = 0, pw = 1;
        for(int i = 0; i < sz(str); ++i){
            v[i + 1] = (nxt + (str[i] - off + 1) * pw)%MOD;
            nxt = v[i + 1];
            pw = (pw * al)%MOD;
        }
    }

    ll qry(int l, int r){
        if(r < l) return 0;
        ll res = v[r + 1] - v[l];
        return (((ipw[l] * res)%MOD) + MOD)%MOD;
    }
};
ll res = 0;
int n;
unordered_set<ll> st;
vector<string> v;
vector<rolling_hash> v1, v2;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; ++i){
        string str; cin >> str;
        rolling_hash r1(MOD1, 31, 'a');
        r1.hash(str);
        v1.pb(r1);
        rolling_hash r2(MOD2, 31, 'a');
        r2.hash(str);
        v2.pb(r2);
        ll hh = EX * r1.qry(0, sz(str) - 1) + r2.qry(0, sz(str) - 1);
        st.insert(hh);
        v.pb(str);
        // cout << str << "\t" << hh << "\n";
        // if(str == "cyx") cout << r1.qry(1, 2) << " " << r2.qry(1, 2) << "\n";
    }
    for(int i = 0; i < sz(v); ++i){
        if(sz(v[i]) <= 1) continue;
        vector<bool> wks(26, 0);
        wks[v[i][0] - 'a'] = 1, wks[v[i][1] - 'a'] = 1;
        for(int j = 2; j <= sz(v[i]); ++j){
            for(int k = 0; k < 26; ++k){
                if(!wks[k]) continue;
                ll con = 0;
                ll a = (v1[i].qry(j, sz(v[i]) - 1) * 31 + (k + 1))%MOD1;
                ll b = (v2[i].qry(j, sz(v[i]) - 1) * 31 + (k + 1))%MOD2;
                // if(v[i] == "abcxyx" && j == 4){
                //     cout << v1[i].qry(j, sz(v[i]) - 1) << " " << v2[i].qry(j, sz(v[i]) - 1) << "\n";
                //     cout << k << " " << a << " " << b << " " << a * EX + b << "\n";
                // }
                con = a * EX + b;
                res += (st.count(con) > 0);
            }
            if(j < sz(v[i])) wks[v[i][j] - 'a'] = 1;
        }
    }
    cout << res;
    return 0;
}

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

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int n = cin.nextInt();
			if(n==0){
				break;
			}
			Team[] t = new Team[n];
			for(int i = 0;i<n;i++){
				String str = cin.next();
				int win=0,lose=0;
				for(int j = 0;j<n-1;j++){
					int a = cin.nextInt();
					if(a==0){
						win++;
					}
					else if(a==1){
						lose++;
					}
				}
				t[i]=new Team(str,win,lose,i);
			}
			Arrays.sort(t);
			for(int i = 0;i<n;i++){
				System.out.println(t[i].name);
			}
		}
	}
}
class Team implements Comparable{
	String name;
	int win;
	int lose;
	int num;
	Team(String str,int a,int b,int c){
		name=str;
		win=a;lose=b;num=c;
	}
	public int compareTo(Object o) {
		Team t = (Team)o;
		if(t.win==this.win){
			if(this.lose-t.lose==0){
				return this.num-t.num;
			}
			else{
				return this.lose-t.lose;
			}
		}
		else{
			return t.win-this.win;
		}
	}
}

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

using namespace std;

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

int main() {
	string ser;
	int n, ans = 0;
	cin >> ser >> n;
	REP(i, n) {
		string str;
		cin >> str;
		str += str;
		if (str.find(ser) != string::npos) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1212
import sys
import time
bbn=1000000007
	
#+++++

def gcb(a,b):
	if b == 0:
		return a
	else:
		gcb(b, b%a)
	
def main():
	#st=time.time()
	a, b , c = map(int, input().split())
	for i in range(100000):
		if a * i % b == c:
			return 'YES'
	return 'NO'

	#print(gcb(b,))
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 38508
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=0;i<=VMAX;i++){
    C[i]=0;
  }
  for(i=0;i<n;i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=VMAX;i++){
    C[i]=C[i]+C[i-1];
  }
  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 9656
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
		bool answer = false;
    int differentCount = 0;

    for(int i = 0; i < n; i++)
    {
      if(nums[i] != i+1) differentCount++;
    }

    if(differentCount <= 2) answer = true;

		Console.WriteLine(answer?"YES":"NO");
	}
}

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main() {
  int n, d;
  cin >> n >> d;
  int x[n][d];
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < d; j++) {
      cin >> x[i][j];
    }
  }

  int count = 0;
  for(int i = 0; i < n-1; i++) {

    for(int j = i+1; j < n; j++) {
      int val = 0;
      for(int k = 0; k < d; k++) {
        val += pow(x[i][k]-x[j][k], 2);
      }
      if(sqrt(val) == int(sqrt(val))) {
        count++;
      }
    }
  }

  cout << count << endl;

}


Measured memory_bytes: 256
S = list(raw_input())

if len(set(S)) == 1:
    print 0
else:
    while S[-1] == S[-2]:
        del S[-1]
    del S[-1]

    count = 1
    for i in xrange(len(S)-1):
        if S[i] != S[i+1]:
            count += 1
    print count


Measured memory_bytes: 3460
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
a = ['','']
a[0] = str(n) * m
a[1] = str(m) * n
print(sorted(a)[0])

Measured memory_bytes: 65644
#include <iostream>
#include <string>
#include <numeric>

using namespace std;

int main() {
    int n, a, b, ans = 0;
    cin >> n >> a >> b;
    for (int i = 1; i <= n; ++i) {
        string s = to_string(i);
        int v = accumulate(s.begin(), s.end(), 0) - '0' * s.size();
        if (v >= a && v <= b) ans += i;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define int long long
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=0;i<n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[30][30],k,flag,t,dp[27][(1<<21)+2];
int cev;
string s;
vector<int> v;

inline int add(int x,int y){
	if(x+y>=mod)return x+y-mod;
	return x+y;
}

inline int f(int sira,int mask){
	int cevv=0;
	if(mask==(1<<n)-1)return 1;
	if(sira>=n)return 0;
	if(~dp[sira][mask])return dp[sira][mask];
	if((mask&(1<<sira))==1){cevv=add(cevv,f(sira+1,mask));}
	else{
		FOR{
			if((mask&(1<<i))==0 && a[sira][i]==1)cevv=add(cevv,f(sira+1,(((mask|(1<<i))))));
		}
	}
	return dp[sira][mask]=cevv;
}

main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%lld",&n);
	FOR{
		for(int j=0;j<n;j++)scanf("%lld",&a[i][j]);
	}
	printf("%lld\n",f(0,0));
	return 0;
}


Measured memory_bytes: 444800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,a,b,c,cnt=0,arr[10000],sum=0,pk;
     cin>>a>>b;
     for(int i=0;i<a;i++)
     {
         cin>>arr[i];
         sum+=arr[i];
     }
     for(int i=0;i<a;i++)
     {
         pk=ceil(sum/(4.0*b));
         if(arr[i]>=pk)
            cnt++;
     }
     //cout<<cnt<<endl;
     if(cnt>=b)
        cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int intArray[3] = { 0, 0, 0 };
    
    // input
    for( int i = 0; i < 3; ++i )
    {
        std::cin >> intArray[i];
    }
    
    // sort
    for( int i = 0; i < 3; ++i )
    {
        int min = intArray[i];
        
        for( int j = i; j < 3; ++j )
        {
            if( min > intArray[j] )
            {
                intArray[i] = intArray[j];
                intArray[j] = min;
                min = intArray[i];
            }
        }
    }
    
    // output
    for( int i = 0; i < 3; ++i )
    {
        if( 2 == i )
        {
            std::cout << intArray[i] << std::endl;
        }
        else
        {
            std::cout << intArray[i] << " ";
        }
    }    
    
    return 0;
}


Measured memory_bytes: 3084