akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll N;
    if (!(cin >> N)) { return; }
    ll M;
    cin >> M;
    vector<ll> X;
    for (int i = 0; i < M; ++i) {
        ll tmp;
        cin >> tmp;
        X.push_back(tmp);
    } // end i

    sort(X.begin(), X.end());
    vector<ll> d;
    for (int i = 1; i < X.size(); ++i) {
        d.push_back(X[i] - X[i-1]);
    } // end i
    ll ans = X.back() - X.front();
    sort(d.rbegin(), d.rend());
    for (int i = 0; i < N - 1 && i < d.size(); ++i) {
        ans -= d[i];
    } // end i
    cout << ans << endl;

}

int main(int argc, char *argv[]) {
    cout << setprecision(16) << scientific;
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    while (cin) { solve(cin); }
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
main()
{
	int x;
	scanf("%d",&x);
	for(int i=1;i<=x;i++)
	{
		int c=0;
		for(int m=1;m<sqrt(i);m++)
		{
			for(int n=1;n<sqrt(i);n++)
			{
				int b=(sqrt(4*i-3*m*m-3*n*n-2*m*n)-(m+n))/2;
				if(b<=0)break;
				if((m*m+n*n+b*b+m*n+m*b+n*b)==i)c++;
			}
		}
		if(c==0)printf("0\n");
		else printf("%d\n",c);
	}
}

Measured memory_bytes: 3748
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include<map>
#include <sstream>
#include <deque>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
const int M = 1e9 + 7;
#define ll long long int
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
using namespace std;

//insta  -------  __ansh7
//MSDIAN




int main()
{
    fastio

        ll a,b,c;
        cin>>a>>b>>c;

        ll count=0;

        for(ll i=a;i<=b;i++)
        {
            if(i%c==0)
            {
                count++;
            }
        }

        cout<<count<<"\n";




  

  
    
 



    




    return 0;
}

Measured memory_bytes: 3644
import numpy as np
N = int(input())
X = np.array(list(map(int,input().split(" "))))

energy = np.sum((X - X[0])**2)

X_max,X_min = np.max(X),np.min(X)
for i in range(X_min,X_max):
    energy_sum = np.sum((X-i)**2)
    if energy > energy_sum:
        energy = energy_sum

print(energy)

Measured memory_bytes: 21896
#include<stdio.h>
#include<math.h>
	
	int main()
	{
		int n;
		int A[102];
		int mean1,mean2;
		int sum = 0;
		float m;
		scanf("%d",&n);
		int i;
		for(i=0;i<n;++i)
		{
			scanf("%d",&A[i]);
			sum = sum + A[i];
		}
		
		m = (float)sum/n ;
		mean1 = ceil(m);
		mean2 = floor(m);
		int min1= 0 ,min2 = 0;
		for(i = 0;i<n;++i)
		{
			min1 = min1 + (mean1 - A[i])*(mean1- A[i]);
			min2 = min2 + (mean2 - A[i])*(mean2 - A[i]);
		}
		
		if(min1 > min2)
		{
			printf("%d",min2);
		}
		else
		{
			printf("%d",min1);
		}
		
		
		return 0;
	}

Measured memory_bytes: 128
import math
import collections
import numpy as np

def combinations_count(n, r):
    if n <= 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

c = collections.Counter(A)
ans = 0
for v in c.values():
    if v > 1:
        ans += v*(v-1)//2

for i in range(N):
    v = c[A[i]]
    print(ans + (v-1)*(v-2)//2 - v*(v-1)//2)

Measured memory_bytes: 34156
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

const int LOG_A = 61;

int basis[LOG_A];
int sz;

void insertVector(int mask) {
	for(int i = 0; i < LOG_A; i++) {
		if((mask & (1LL << i)) == 0) {
			continue;
		}
		if(!basis[i]) {
			basis[i] = mask;
			++sz;
			return;
		}
		mask ^= basis[i];
	}
}

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

	int t;
	cin >> t;
	while(t--) {
		memset(basis, 0, sizeof(basis));
		sz = 0;
		int n;
		cin >> n;
		int a[n];
		for(int i = 0; i < n; i++) {
			cin >> a[i];
		}
		string s;
		cin >> s;
		int ans = 0;
		for(int i = n - 1; i >= 0; i--) {
			if(s[i] == '0') {
				insertVector(a[i]);
			}
			else {
				for(int j = 0; j < LOG_A; j++) {
					if(a[i] & (1LL << j)) {
						a[i] ^= basis[j];
					}
				}
				if(a[i]) {
					ans = 1;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3440
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
	int h, w;
	char a[100][101];
	bool fx[100], fy[100];

	cin >> h >> w;

	for (int i = 0; i < h; i++)
		cin >> a[i];

	memset(fx, 0, 100);
	memset(fy, 0, 100);

	for (int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++)
			if (a[i][j] == '#') {
				fy[i] = 1;
				break;
			}
	}

	for (int j = 0; j < w; j++) {
		for (int i = 0; i < h; i++)
			if (a[i][j] == '#') {
				fx[j] = 1;
				break;
			}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (fy[i] && fx[j])
				cout << a[i][j];
		}
		if(fy[i])
			cout << endl;
	}

	return 0;
}


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

using namespace std;

int h[100005];
int n;

int dp[100005];

int solve(int i){

    if (i >= n-1) return 0;
    
    if(dp[i] != -1){
        return dp[i];
    }
    
    int a = 1e9+7;
    int b = 1e9+7;
    

    a = solve(i+1) + abs(h[i]-h[i+1]);

    if(i < n-2){
        b = solve(i+2) + abs(h[i]-h[i+2]);
    }
    
    return dp[i] = min(a,b);

}


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

}

Measured memory_bytes: 4096
using System;
class Program
{
  static void Main(string[] args)
  {
    int n,d,x;
    int p=0;
    int[] a = new int[1002];
    int[] b = new int[1002];

    n = int.Parse(Console.ReadLine());
    string[] input = Console.ReadLine().Split(' ');
    d  = int.Parse(input[0]);
    x =  int.Parse(input[1]);

    for (int i=1;i<n+1;i++){
        a[i]=int.Parse(Console.ReadLine());
        b[i]=1;
    }

    for (int i=1;i<=n;i++){
      for (int j=1;j<=d;j++){
        if (b[i] == j){
          p++;
          b[i]+=a[i];
        }
      }
    }
    p+=x;

    Console.WriteLine(p);


  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,f[3030][3030],a[3030];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(n&1)
			f[i][i]=a[i];
		else
			f[i][i]=a[i];
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=n-i;j++)
		{
			if(((i+1)&1)==(n&1) && i!=1)
				f[j][i+j]=max(f[j+1][j+i]+f[j][j],f[j][j+i-1]+f[j+i][j+i]);
			else if(((i+1)&1)==(n&1) && i==1)
				f[j][i+j]=max(f[j+1][j+i]-f[j][j],f[j][j+i-1]-f[j+i][j+i]);
			else
				f[j][i+j]=min(f[j+1][j+i]-f[j][j],f[j][j+i-1]-f[j+i][j+i]);
		} 
	}
	cout<<f[1][n]<<endl;
	return 0;
}

Measured memory_bytes: 71936
var sx,sy,tx,ty,i:Integer;
begin
	read(sx,sy,tx,ty);
	inc(sx);
	inc(sy);
	for i:=sy to ty do write('U');
	for i:=sx to tx do write('R');
	for i:=sy to ty do write('D');
	for i:=sx to tx do write('L');
	write('L');
	for i:=sy to ty do write('U');
	write('UR');
	for i:=sx to tx do write('R');
	write('DR');
	for i:=sy to ty do write('D');
	write('DL');
	for i:=sx to tx do write('L');
	write('U');
end.


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();
        if(s.equals(u)){
            a--;
        }else{
            b--;
        }
        System.out.print(a + " " + b);
        sc.close();
    }
}

Measured memory_bytes: 38720
a, b, c, k = map(int, input().split())
ans = 0
if a > k:
    ans+= 1*k
elif a < k:
    ans += 1*a
    if b< k-a:
        ans+= -1*(k-a-b)
    else:
        ans = ans
        
else:
    ans += 1*a
print(ans)

Measured memory_bytes: 9168
x,n = map(int,input().split())
if n != 0:
    P = list(map(int,input().split()))
else:
    P = []
tmp = 999
ans = 0
for i in range(-1,102):
    if tmp > abs(x-i):
        if not i in P:
            tmp = abs(x-i)
            ans = i
print(ans)

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

const int mod = 1e9 + 7;

int N, M, K, X;

vector<vector<int> > cc[2];
int dp(int x, int n, int t) {
    if(x == X) return n == 0 && t;
    int &ret = cc[t][x][n];
    if(ret != -1) return ret;

    ret = 0;
    if(n % (K - 1) == 0 && n / (K - 1) <= X - x && t) ret++;
    for(int i = 0; i < K; i++) {
        if(i > n) break;
        ret += dp(x + 1, n - i, i != 0);
        ret %= mod;
    }
    return ret;
}

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

    X = (N + M - 1) / (K - 1);

    cc[0] = cc[1] = vector<vector<int> >(X, vector<int>(N + 1, -1));
    cout << dp(0, N, 0);
}


Measured memory_bytes: 63232
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Long> l = new ArrayList<Long>();
		l.add(2L);
		l.add(1L);
		long ans = 0;
		for(int i = 2; i <=n; i++) {
			 ans = l.get(i-1)+l.get(i-2);
			 l.add(ans);
		}
		System.out.println(l.get(l.size()-1));
	}

//	public static long lucas(int n) {
//		if(n==0) {
//			return 2;
//		}
//		else if(n==1) {
//			return 1;
//		}
//		else {
//			return lucas(n-1)+lucas(n-2);
//		}
//	}
}


Measured memory_bytes: 22868
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1165&lang=jp

#include <iostream>
#include <stdio.h>
#include <algorithm> // fill
#include <utility> // pair

using namespace std;

const int dir[4][2] = { {-1, 0}, {0, -1}, {1, 0}, {0, 1} };

int main() {
  int N;
  while (scanf("%d", &N) != EOF && N) {
    int tiles[210][2];
    int max[2] = {1, 1};
    int min[2] = {0, 0};
    int n, d;
    tiles[0][0] = 0;
    tiles[0][1] = 0;
    for (int i=1; i<=N-1; i++) {
      // cerr << "i = " << i << endl;
      scanf("%d%d", &n, &d);
      for (int j=0; j<2; j++) {
	int temp = tiles[n][j];
	temp += dir[d][j];
	tiles[i][j] = temp;
	// cerr << temp << " ";
	if (max[j] < temp+1) max[j] = temp+1;
	if (min[j] > temp) min[j] = temp;
      }
      // cerr << endl;
    }
    // cerr << "max: " << max[0] << " " << max[1] << endl;
    // cerr << "min: " << min[0] << " " << min[1] << endl;
    printf("%d %d\n", max[0] - min[0], max[1] - min[1]);
  } 
}

Measured memory_bytes: 1172
# 符号が異なる数同士の引き算をすれば絶対値が大きくなる
# 基本は負から正を引いて大きな負の数を作る
# 最後だけ正から負を引いて大きな正の数を作る
# 正と正しか存在しない場合は最も小さい数からその他の数を引くことで負の数を作れる
# 負と負しか存在しない場合は最も大きい数からその他の数を引くことで正の数を作れる
# 正のリストと負のリスト両方を管理する
# 0は何も影響を与えないのでとりあえず正のリストに入れておく

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

if len(A) == 2:
  x = max(A)
  y = min(A)
  print(x-y)
  print(x,y)
  exit(0)

plusA = []
minusA = []
for a in A:
  if a >= 0:
    plusA += [a]
  else:
    minusA += [a]
    
method = [] # 計算過程をメモ
if len(plusA) == 0:
  minusA = sorted(minusA) # 最も小さな数を取り出すため
#  print("minusA",minusA)
  x = minusA.pop()
  y = minusA.pop()
#  print("x",x,"y",y)
  method.append([x,y])
  plusA.append(x-y)
#  print("plusA",plusA,"minusA",minusA,"method",method)
elif len(minusA) == 0:
  plusA = sorted(plusA)[::-1] # 最も小さな数を取り出すため
  x = plusA.pop()
  y = plusA.pop()
  method.append([x,y])
  minusA.append(x-y)
  
while True:
  if len(minusA) + len(plusA) == 1:
    print(x-y)
    for m in method:
      print(*m)
    break
  if len(plusA) == 1:
    # 正の数が一つのときは、この数から残りの負の数を引いていく
    x = plusA.pop()
    y = minusA.pop()
    method.append([x,y])
    plusA.append(x-y)
  else:
    # 正の数が複数あるときは、負の数を作り続ける
    x = minusA.pop()
    y = plusA.pop()
    method.append([x,y])
    minusA.append(x-y)


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

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

using namespace std;

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

    int A, B;
    cin >> A >> B;
    cout << max(max(A + B, A - B), A * B) << '\n';
}

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

int main(){
    int k;
    string s;
    cin >>k>>s;
    if(s.size()<=k){
        cout << s <<endl;
    }else{
        for(int i=0;i<k;i++){
            cout << s[i];
        }
        cout << "..." <<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits.h>
using namespace std;
using ll=long long;
int main(){
    int n,k;
    cin>>n>>k;
    vector<bool> t(n,false);
    for(int i=0;i<k;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int s;
            cin>>s;
            t[s-1]=true;
        }
    }
    int ret=0;
    for(int i=0;i<n;i++){
        if(t[i]==false)ret++;
    }
    cout<<ret<<endl;
}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	
	int N[4];
	cin >> N[0] >> N[1] >> N[2] >> N[3];
	
	sort(N, N + 4);
	
	if(N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	
	return 0;
}


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

void selectionSort(vector<int> &A, int N, int &count) {
  for(int i = 0; i <= N - 1; i++) {
    int minj = i;
    for(int j = i; j <= N - 1; j++) {
      if(A[j] < A[minj]) {
      	minj = j;
      }
    }
    if (minj != i) {
      swap(A[minj], A[i]);
      count ++;
    }
  }
}

int main() {
  int N;
  int count = 0;
  cin >> N;
  vector<int> A(N);
  rep (i, N) cin >> A.at(i);
  selectionSort(A, N, count);
  rep (i, N) {
    cout << A.at(i);
    if (i != A.size() - 1) {
    	cout << " ";
    }
  }
  cout << endl;
  cout << count << endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int c=0;
    cin>>s;
    for(int i=0;s[i];i++)
    {
        if(s[i]=='7')
            c++;
    }
    if(c)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


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

int main() {
  int a,b,M,m;
  cin >> a >> b;
  M = max(a,b);
  m = min(a,b);
  for(int i = 0;i < M;i++){
    cout << m;
  }
  cout << "" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N = 105;
long long a[N];
long long gcd(long long a, long long b)
{
	return b ? gcd(b, a % b) : a;
}
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 2; i <= n; i++)
		for (int j = 1; j < i; j++)
			a[i] /= gcd(a[i], a[j]);
	long long ans = 1;
	for (int i = 1; i <= n; i++)
		ans *= a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  int n;cin >> n;
  vector<pair<int,int>> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i].first >> v[i].second;
  }
  sort(ALL(v));
  vector<int> vv(n);
  for(int i=0;i<n;i++) vv[i] = v[i].second;
  sort(ALL(vv));
  int ans = 0;
  // cout << vv[n/2] << " " << v[n/2] << endl;
  if(n%2) ans = vv[n/2] - v[n/2].first + 1;
  else{
    ans = vv[n/2]+vv[(n-1)/2]-(v[n/2].first+v[(n-1)/2].first)+1;
  }
  cout << ans << endl;
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

Measured memory_bytes: 5584
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
	int c = 0, cc = s.length() - 1;
	int res = 0;
	while (c <= cc) {
		res += ((s[c] == s[cc]) ? 0 : 1);
		++c;
		--cc;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

struct edge {
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> c(10, vector<int>(10));
  rep(i, 10) {
    rep(j, 10) {
      cin >> c[i][j];
    }
  }

  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 0; k < 10; k++)
        c[j][k] = min(c[j][k], c[j][i] + c[i][k]);

  vector<int> cnt(10);
  vector<vector<int>> A(H, vector<int>(W));
  rep(i, H) {
    rep(j, W) {
      cin >> A[i][j];
      if (A[i][j] == -1)
        continue;
      cnt[A[i][j]]++;
    }
  }

  int ans = 0;
  rep(i, 10) {
    ans += c[i][1] * cnt[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int INF=1e10;

int xy[10][2];

double dist(int i, int j) {
    double dx = xy[i][0] - xy[j][0];
    double dy = xy[i][1] - xy[j][1];
    return pow(dx * dx + dy * dy, 0.5);
}

int main() {
	int n;
	double ans = 0;
	cin >> n;
	vector<int> a(n);
	for(int i = 1;i<=n;i++){
		cin >> xy[i][0] >> xy[i][1];
	}
  for(int i = 0; i < n; i++) a[i] = i + 1;
	do {
     for(int i = 0; i < n - 1; i++) ans += dist(a[i], a[i+1]);
  } while(next_permutation(a.begin(), a.end()));
	int Factorial = 1;
  for(int i = 2; i <= n; i++) Factorial *= i;
  cout << fixed << setprecision(10) << ans / Factorial << endl;
}

Measured memory_bytes: 4220
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


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


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

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

  ll ans = 0;
  ll before = a[0];
  ll cnt = 0;
  for(int i = 0; i < n; ++i){
    if(before != a[i]){
      if(cnt > before){
        ans += abs(cnt - before);
      } else if(cnt < before) {
        ans += cnt;
      }
      cnt = 1;
      before = a[i];
      continue;
    }
    cnt++;
  }
  if(cnt > before){
    ans += abs(cnt - before);
  } else if(cnt < before) {
    ans += cnt;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            char[] arr = in.next().toCharArray();
            StringBuilder sb = new StringBuilder();
            Stack<Character> stk = new Stack<>();
            StringBuilder ans = new StringBuilder();
            for (char c : arr) {
                sb.append(c);
                if (c == '(') {
                    stk.push(c);
                } else if (!stk.isEmpty()) {
                    stk.pop();
                } else {
                    ans.append('(');
                }
            }
            while (!stk.isEmpty()) {
                sb.append(')');
                stk.pop();
            }
            out.print(ans.toString() + "" + sb.toString());
        }

    }
}



Measured memory_bytes: 21716
s = int(input())


def f(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return 3 * n + 1

A = [s]

for i in range(1000000):
    a = f(A[-1])
    if a in A:
        print(i+2)
        break
    else:
        A.append(a)


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

int n,pos;
vector<int> pre,in,post;

void rec(int l , int r) {
  if(l >= r)return ;
  int root = pre[pos++];
  int m = distance(in.begin(),find(in.begin(), in.end(),root));
  rec(l,m);
  rec(m+1,r);
  post.push_back(root);
}

void solve() {
  pos = 0;
  rec(0,pre.size());
  for(int i = 00;i<n;i++) {
    if(i) cout << " ";
    cout << post[i];
  }
  cout <<endl;
}

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

  for(int i  = 0; i<n;i++) {
    cin >>k;
    pre.push_back(k);
  }
  for(int i=0;i<n;i++){
    cin >> k;
    in.push_back(k);
  }

  solve();

  return 0;
}

Measured memory_bytes: 3160
total = 0
m = 10
for _ in range(5):
  t = int(input())
#  print(t)
  total += ((t-1) // 10 + 1) * 10
#  print(total)
  if 0 < t % 10 < m:
    m = t % 10
#print(m)
print(total-10+m)

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

int main() {
  int N;
  int can_view = 0;
  cin >> N;
  vector<int> height(N);
  for (int i = 0; i < N; i++) {
    cin >> height.at(i);
  }
  int kizyun = height.at(0);
  for (int i = 0; i < N; i++) {
    if(height.at(i) > kizyun){
      can_view++;
      kizyun = height.at(i);
    }else if(height.at(i) == kizyun){
      can_view++;
    }
  }
  cout << can_view << endl;
  
}

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

int main()
{
    long long x,y,z,sum=0;
    cin>>x>>y;
    while(y--)
    {
        cin>>z;
        sum=sum+z;
    }
    if(sum>x)
        cout<<-1<<endl;
    else if(sum<x)
        cout<<x-sum<<endl;
    else
        cout<<0<<endl;

}






Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;//ans=sum^part+part
typedef long long ll;
const int N=1e5+4;
ll a[N],b[64],sum,cur;
int pos[64],tim;
int n;
inline void add(ll x) {
	for (int i=1;i<=tim;++i) {
		if (!((x>>pos[i])&1)) continue;
		else if (!b[pos[i]]) {b[pos[i]]=x;break;}
		else x^=b[pos[i]];
	}
}
int main() {
	scanf("%d",&n);
	for (register int i=1;i<=n;++i) {
		scanf("%lld",&a[i]);
		sum^=a[i];
	}
	for (int i=60;~i;--i)
		if (!((sum>>i)&1))
			pos[++tim]=i;
	for (register int i=1;i<=n;++i)
		add(a[i]);
	for (int i=1;i<=tim;++i)
		if (!((cur>>pos[i])&1))
			cur^=b[pos[i]];
	printf("%lld\n",(sum^cur)+cur);
	return 0;
}

Measured memory_bytes: 1024
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
if n != 0:
  p = sorted(map(int,input().split()))
aa = []
for i in range(1,101):
  if not i in p:
    aa.append(i)
bb = []
if len(aa) == 0:
  if abs(x-(0)) <= abs(x-101):
    print(0)
    exit()
  else:
    print(101)
    exit()
else:
  for A in aa:
    eee = abs(x-A)
    bb.append(eee)

ans = bb.index(min(bb))
if abs(x-(0)) <= min(bb):
  print(0)
  exit()
elif abs(x-101) < min(bb):
  print(101)
  exit()
else:
  print(aa[ans])
  exit()

Measured memory_bytes: 9240
s=0
rs=0
m=9
for i in range(5):
    n=int(input())
    rs+=n%10
    if n%10!=0:
        m=min(m,n%10)
        n=(n//10+1)*10
    s+=n
if rs==0:
    m=10
print(s-10+m)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int MAX=1000005;
int dp[MAX];
int dp2[MAX];
vector<int> pol,pol2;
int main(void){
    dp[0]=0;dp2[0]=0;
    int cnt=1;
    // printf("start\n");
    while((cnt*(cnt+1)*(cnt+2))/6<MAX-1){
        int a = (cnt*(cnt+1)*(cnt+2))/6;
        pol.push_back(a);
        if(a%2==1)pol2.push_back((cnt*(cnt+1)*(cnt+2))/6);
        cnt++;
    }
    // cout << pol.size() << endl;
    // printf("dp start\n");
    for(int i=1;i<MAX;i++){
        int tmp=1<<30;
        int cur=0;
        while(cur<pol.size()&&pol[cur]<=i){
            tmp=min(tmp,dp[i-pol[cur]]+1);
            cur++;
        }
        dp[i]=tmp;
    }
    for(int i=1;i<MAX;i++){
        int tmp=1<<30;
        int cur=0;
        while(cur<pol2.size()&&pol2[cur]<=i){
            tmp=min(tmp,dp2[i-pol2[cur]]+1);
            cur++;
        }
        dp2[i]=tmp;
    }
    // printf("stand by\n");
    while(true){
        int n;
        cin>>n;
        if(n==0)return 0;
        printf("%d %d\n",dp[n],dp2[n]);
    }
}


Measured memory_bytes: 10896
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	
	int a,b;char op;
	while(true){
	cin>>a>>op;
	if(op=='?')break;
	cin>>b;
	if(op=='+')cout<<a+b<<endl;
	if(op=='-')cout<<a-b<<endl;
	if(op=='*')cout<<a*b<<endl;
	if(op=='/')cout<<a/b<<endl;
	}

return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
	int N;
	cin >> N;
	vll A(N,0);
	for(int i=0; i<N; i++){
		ll a;
		cin >> a;
		A[i]=a*2;
	}

	for(int i=0; i<N-1; i++){
		if(i%2==1){
			A[N-1]+=A[i];
		}else{
			A[N-1]-=A[i];
		}
	}
	A[N-1]/=2;
	for(int i=N-1; i>0; i--){
		A[i-1]-=A[i];
	}

	for(int i=0; i<N; i++){
		cout << A[i] << " ";
	}
	cout << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  ll x;cin>>x;

  ll ans=(x/11)*2;
  x%=11;

  if(x==0)out(ans);
  else out(ans+((x>6)?2:1));

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	double max = 0;
	double min = 9999999;
	double height;
	while(scanf("%lf",&height) != EOF){
		if(height > max){
			max = height;
		}
		if(min > height){
			min = height;
		}
	}
	printf("%.1f\n",max - min);
	return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
#define int long long
int wt[1000006];
int cost[1000006];
int dp[101][100005];
int knapsack(int i, int w) {
	if (i == -1 or w == 0)
		return 0;
	if (dp[i][w] != -1)
		return dp[i][w];
	if (w < wt[i])
		return dp[i][w] = knapsack(i - 1, w);
	return dp[i][w] = max(knapsack(i - 1, w - wt[i]) + cost[i], knapsack(i - 1, w));

}
int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	memset(dp, -1, sizeof(dp));
	int n;
	cin >> n;
	int cap;
	cin >> cap;
	for (int i = 0; i < n; i++)
		cin >> wt[i] >> cost[i];
	cout << knapsack(n - 1, cap);
	return 0;
}

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

typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> x(M), y(M);
    for(int i=0; i<M; i++){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    
    vector<pair<int,int> > fc(N,{false,1});
    fc[0].first = true;
    
    for(int i=0; i<M; i++){
        if(fc[x[i]].first){
            fc[y[i]].first = true;
            if(fc[x[i]].second==1) fc[x[i]].first = false;
            fc[x[i]].second--;
            fc[y[i]].second++;
        } else {
            fc[x[i]].second--;
            fc[y[i]].second++;
        }
    }
    
    int ans=0;
    for(int i=0; i<N; i++){
        if(fc[i].first) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1792
(let ((s (read-line)))
  (cond ((string= s "SUN")
         (format t "7~%"))
        ((string= s "MON")
         (format t "6~%"))
        ((string= s "TUE")
         (format t "5~%"))
        ((string= s "WED")
         (format t "4~%"))
        ((string= s "THU")
         (format t "3~%"))
        ((string= s "FRI")
         (format t "2~%"))
        ((string= s "SAT")
         (format t "1~%"))))


Measured memory_bytes: 23420
#include <cstdio>

int main(void){
char inp[2][5];
int i,j,p,q;
while(1){
scanf("%s%s",inp[0],inp[1]);
if(inp[0][1]==0)break;
p=0;q=0;

for(i=0;i<4;i++){
if(inp[0][i]==inp[1][i])p++;
for(j=0;j<4;j++){
if(inp[0][i]==inp[1][j])q++;
}
}
printf("%d %d\n",p,q-p);
}
return 0;
}

Measured memory_bytes: 968
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	int n;
	cin >> n;
	ll ans = 1;
	bool judge = true;
	rep(i, 0, n) {

		ll a;
		cin >> a;
		if (a == 0) {
			cout << 0 << endl;
			return 0;
		}
		if (a <= LINF / ans) {
			ans *= a;
		}
		else {
			judge = false;
		}


	}
	if (judge)cout << ans << endl;
	else cout << -1 << endl;
}
	

Measured memory_bytes: 3672
from fractions import gcd
N = int(input())
A = [int(i) for i in input().split()]
mod = 10**9 +7
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
cur_prime = {}
for i in range(N):
    S = factorization(A[i])
    for j in range(len(S)):
        if S[j][0] not in cur_prime:
            cur_prime[S[j][0]] = S[j][1]
        else:
            cur_prime[S[j][0]] = max(S[j][1],cur_prime[S[j][0]])
A_lcm = 1
key = list(cur_prime.keys())
value = list(cur_prime.values())
for i in range(len(key)):
    for j in range(value[i]):
        A_lcm *= key[i]
        A_lcm %= mod
ans = 0
for i in range(N):
    ans += A_lcm*pow(A[i],mod-2,mod)
    ans %= mod
print(ans)


Measured memory_bytes: 73172
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> p(M);
  std::vector<std::string> S(M);
  for (int i = 0; i < M; i++)
  {
    scanf("%lld", &p[i]);
    std::cin >> S[i];
  }
  vector<ll> a(N + 1, 0), w(N + 1, 0);
  for (int i = 0; i < M; ++i)
  {
    if (S[i] == "AC")
      a[p[i]]++;
    else if (a[p[i]] == 0)
      w[p[i]]++;
  }
  ll ac = 0, wa = 0;
  for (int i = 0; i <= N; ++i)
  {
    if (a[i] > 0)
    {
      ac++;
      if (w[i] > 0)
        wa += w[i];
    }
  }
  cout << ac << ' ' << wa << endl;

  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
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 m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;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>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T>inline int bs(int g,int k,T c){while(abs(k-g)>1){int m=(g+k)/2;(c(m)?k:g)=m;}return k;}
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;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int n, k;
    cin >> n >> k;
    vector<int> cnt(n);
    for(int i = 0; i < k; ++i){
        int d; cin >> d;
        for(int j = 0; j < d; ++j){
            int a; cin >> a;
            cnt[--a]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(cnt[i] == 0)  ++ans;
    }
    cout << ans << '\n';
    
    
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
 int h1,h2,m1,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  ///////
  int ans=0;
  ans+=(h2-h1)*60;
  ans+=(m2-m1);
  ans-=k;
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
n=int(input())
p=[int(i) for i in input().split()]

ans=0

if p[0]==1:
    ans+=1
    p[1]=1

for i in range(1,n):
    if p[i]==i+1:
        if p[i-1]==i:
            ans+=1
            p[i]=i
        else:
            if i+1!=n:
                if p[i+1]!=i+2:
                    ans+=1
                    p[i]=p[i-1]
            else:
                ans+=1

print(ans)

Measured memory_bytes: 14008
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a ==b && a!=c){
            System.out.println(c);
        }else if(a == c){
            System.out.println(b);
        }else{
            System.out.println(a);
        }
    }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x, y;
  bool operator < (const P &a )const{
    //if(x!=a.x)
    return y<a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[3101];
int l[441];
int j[441];

long long x,y,z,mod=1000000007;
//string r;
char r[223111];

P u[1];
priority_queue<int> q;
stack<int> s;
//set<P> s;
map<int,int> p;

vector<int> v;

bool as(P a,P b)
{
  //if(a.x!=b.x)
  //return a.x<b.x;
  return a.x<b.x;
}

int main()
{
  scanf("%s",r+1);
  a=strlen(r+1);
  for(int t=1;t<a;t++)
  {
    if(r[t]==r[t+1]||r[t]==r[t+2])
    {
      if(r[t]==r[t+1]) printf("%d %d",t,t+1);
      else printf("%d %d",t,t+2);
      return 0;
    }
  }
  puts("-1 -1");
}
//0
//16



Measured memory_bytes: 384
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

main :: IO ()
main = do
  n <- readLn
  ss <- map head . words <$> getLine
  putStrLn $ solve n ss

solve :: Int -> [Char] -> String
solve _ ss = if any (== 'Y') ss then "Four" else "Three"


Measured memory_bytes: 508
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
// ミント
const int mod = 1e9+7 ;
//998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}   ;
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

int main(){
   ll n,k ;
   cin>>n>>k ;
  mint ans= 0;
  vector<mint> B(k+1) ;

  for(ll i=k;i>=1;i--){
   ll a= k/i ;
      mint sum = modpow(a,n) ;
    for(ll p=i*2;p<=k;p+=i){
      sum-=B[p] ;
    }
    B[i]=sum ;
    mint j= i ;
    ans+=sum*j ;
   }
   cout<< ans<<endl ;
   
       return 0;
  }
   

Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,c;
  string b;
  while(1){
    cin>>a>>b>>c;
    if(b=="?") break;
    else if(b=="+") cout<<a+c<<endl;
    else if(b=="-") cout<<a-c<<endl;
    else if(b=="*") cout<<a*c<<endl;
    else if(b=="/") cout<<a/c<<endl;
  }
  return(0);
}

Measured memory_bytes: 3140
s = input()
t = input()
ls = len(s)
lt = len(t)

def match(k):
    for i in range(lt):
        if t[i] != s[i+k] and s[i+k] != '?':
            return False
    return True

c = -1
for i in range(ls-lt+1):
    if match(i):
        c = i

if c == -1:
    print('UNRESTORABLE')
else:
    ans = s[:c]
    ans += t
    ans += s[len(ans):]
    print(ans.replace('?', 'a'))


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vc> a(n, vc(m));
  for (auto &i : a) for (auto &j : i) cin >> j;
  int ans = 0;
  for (int i = 0; i < (1 << n); i++)
  for (int j = 0; j < (1 << m); j++) {
    vector<vc> b(all(a));
    for (int k = 0; k < n; k++) {
      if (get_bit(i, k)) {
        for (int l = 0; l < m; l++) {
          b[k][l] = '.';
        }
      }
    }
    for (int k = 0; k < m; k++) {
      if (get_bit(j, k)) {
        for (int l = 0; l < n; l++) {
          b[l][k] = '.';
        }
      }
    }
    int cnt = 0;
    for (auto &k : b) for (auto &l : k) {
      if (l == '#') cnt++;
    }
    if (cnt == k) ans++;
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[110];

bool cmp(int a,int b)
{
	return a>b;
}

int main(void)
{
	int sum=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sort(a,a+n,cmp);
	if(a[m-1]<1.0*sum/(4*m))
		printf("No");
	else
		printf("Yes");
	return 0;
}

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


int main(){
	int r,g,b;
	cin >>r>>g>>b;

	if((g*10+b)%4==0){

		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;
 
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

 
int main() {
   ll N,W;
   cin>>N>>W;
   ll w[N+1];
   ll v[N+1];
   ll dp[N+1][W+1];
   
   rep(i,N+1)rep(j,W+1)dp[i][j]=0;

   for(ll i=1;i<=N;i++)cin>>w[i]>>v[i];

   for(ll i=1;i<=N;i++){
       for(ll j=0;j<=W;j++){
       if(j>=w[i]){
           dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
       }
       else{
           dp[i][j]=dp[i-1][j];
       }
       }
   }
   
   cout<< dp[N][W]<< endl;
   return 0;
}

Measured memory_bytes: 79104
#include<iostream>
#define int long long
using namespace std;
const int inf=1e18+1;
int dp[405][405],ar[405],sum[405];
signed main(){
	int n,i,j,k;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
		sum[i]=sum[i-1]+ar[i];
		dp[i][i]=0;
	}
	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			dp[i][j]=inf;
		}
	}
	for(i=1;i<n;i++){
		for(j=1;j<=n-i;j++){
			for(k=j;k<i+j;k++){
				dp[j][i+j]=min(dp[j][j+i],dp[j][k]+dp[k+1][i+j]+sum[i+j]-sum[j-1]);
			}
		}
	}
	cout<<dp[1][n];
}

Measured memory_bytes: 1536
N, M = map(int, input().split())
X = list(map(int, input().split()))
t = sorted(X, reverse=True)
h = [0] * M
for i in range(1, M):
    h[i] = abs(t[i - 1] - t[i])

tmp = sorted(h, reverse=True)
print(sum(tmp[N - 1:]))

Measured memory_bytes: 54440
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    n, a, b = map(int, input().split())

    ans = 0
    for n in range(n + 1):
        keta = len(str(n))
        wa = 0
        for m in range(keta):
            tmp = str(n)
            wa = wa + int(tmp[-m-1])
        if a <= wa <= b:
            ans = ans + n

    print(ans)


Measured memory_bytes: 9088
#include <string>
#include <algorithm>
#include <cassert>
#include <functional>
#include <map>
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;
int main()
{
	int n,m;
	cin >> n>> m;
	long long ans = 0;
	vector <vector<int>> b(m);
	for (int i=0; i < n; i++ ) {
		int x, y;
		cin >> x>> y;
		if (x < m + 1) {
			b.at(x - 1).push_back(y);
		}
	}
	priority_queue <int> a;
	for (int i = 0; i < m; i++) {
		while (!b.at(i).empty()) {
			a.push(b.at(i).at(b.at(i).size() - 1));
			b.at(i).pop_back();
		}
		if (!a.empty()) {
			ans += a.top();
			a.pop();
		}
	}
	cout << ans << endl;
}


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

int main() {
  string S;
  cin >> S;
  if (S=="Sunny") {
    cout << "Cloudy" << endl;
  }
  else if (S=="Cloudy") {
    cout << "Rainy" << endl;
  }
  else {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 3624
import math
import fractions

n = list(map(int, input().split()))
n = n[0]
b = list(map(int, input().split()))

b.sort()

if (n%3==0):
    flag = 1
    for i in range(3):
        for j in range(n//3-1):
            if(b[(n//3)*i + j] != b[(n//3)*i + j+1]):
                flag *= 0
            if(b[(n//3)*2]^b[n//3]!=b[0]):
                flag *= 0
    if(flag==1):
        ans="Yes"
    else:
        ans="No"
else:
    if(sum(b)==0):
        ans="Yes"
    else:
        ans="No"
print(ans)

Measured memory_bytes: 16260