akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){ 
    int N;
    cin >> N;
    int sum = 0;
    int n = N;
    while(N!=0){
        sum += N%10;
        N/=10;
    }
    cout << ((n%sum== 0) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
let _ = readLine()!
let ai = readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
var c = 0
for i in ai {
    if i % 2 == 1 {
        c += 1
    }
}

print(c % 2 == 0 ? "YES": "NO")

Measured memory_bytes: 10028
n = gets.to_i
ans = 0
count = 0
cities = []

n.times do 
  cities << gets.split().map(&:to_i)
end

cities.permutation.to_a.each do |array|
  array.each_cons(2) do |(x1, y1), (x2, y2)|
    ans += ((x1-x2)**2 + (y1-y2)**2)**0.5
  end
  count += 1
end

puts ans / count

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

int main(){
	while(1){
		long long int n;
		cin>>n;
		if(n==1) break;
		cout<<n<<':';
		vector<bool> a(n+1,true);
		a[0]=a[1] =false;
		for(long long int i=6;i <= n;i++){
			if(!a[i])continue;
			if( (i*i)%7!=1|| n%i!=0){
				a[i] = false;
				continue;
			}
				
			int j =2;
			while(j*i<=n){
				a[i*j] = false;
				j++;
			}
			cout<<' '<<i;
		}
		cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 3096
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		string a=sc.S;
		string b=sc.S;
		string c=sc.S;
		int ans=0;
		for(int i = 0;i<n;i++) {
			if(a[i]!=b[i]&&a[i]!=c[i]&&c[i]!=b[i]){ans+=2;}
			else if(a[i]==b[i]&&a[i]==c[i]){}
			else{ans++;}
		}
		Console.WriteLine("{0}",ans);
	}
}

class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
}

Measured memory_bytes: 13140
S = input()
a, b = int(S[:2]), int(S[2:])

M = 0
if 1 <= a <= 12:
    M = M | 1
if 1 <= b <= 12:
    M = M | 2

if M & 1 and M & 2:
    print("AMBIGUOUS") 
elif M & 1:
    print("MMYY")
elif M & 2:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
A, B, C = map(int, input().split())
K = int(input())
i = 0
while(A >= B):
    B = B * 2
    i = i + 1
while(B >= C):
    C = C * 2
    i = i + 1
if i <= K:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9052
#include <iostream>
int main(void)
{
	int a, b, c;

	std::cin>>a>>b>>c;

	if(a==b){
		std::cout<<c<<std::endl;
	}else if(b==c){
		std::cout<<a<<std::endl;
	}else if(c==a){
		std::cout<<b<<std::endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }


int N, M, A[9][9];
int check(int y) {
    int win = 0, non = 0;
    rep(x, 0, N) {
        if (A[y][x] == 1) win++;
        else if (A[y][x] < 0 and y != x) non++;
    }
    return win <= (N - 1) / 2 and (N - 1) / 2 <= win + non;
}
int ans = 0;
void dfs(int cu) {
    int x = cu % N;
    int y = cu / N;

    if (cu == N * N) {
        ans++;
        return;
    }

    if (x == y or 0 <= A[y][x]) {
        if (check(y)) dfs(cu + 1);
        return;
    }

    A[y][x] = 1; A[x][y] = 0;
    if(check(y)) dfs(cu + 1);

    A[y][x] = 0; A[x][y] = 1;
    if (check(y)) dfs(cu + 1);

    A[y][x] = A[x][y] = -1;
}
void _main() {
    while (cin >> N) {
        if (N == 0) return;
        cin >> M;
        rep(i, 0, N) rep(j, 0, N) A[i][j] = -1;
        rep(i, 0, M) {
            int a, b; cin >> a >> b;
            a--; b--;
            A[a][b] = 1;
            A[b][a] = 0;
        }

        ans = 0;
        dfs(0);
        printf("%d\n", ans);
    }
}



Measured memory_bytes: 3188
/**
 *    author:  tourist
 *    created: 08.10.2017 15:18:04       
**/
#include <bits/stdc++.h>

using namespace std;

const int md = 1e9 + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
#if !defined(_WIN32) || defined(_WIN64)
  return (long long) a * b % md;
#endif
  unsigned long long x = (long long) a * b;
  unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
  asm(
    "divl %4; \n\t"
    : "=a" (d), "=d" (m)
    : "d" (xh), "a" (xl), "r" (md)
  );
  return m;
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 4010;

int c[N][N];

int main() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (j == 0) c[i][j] = 1; else
      if (i == 0) c[i][j] = 0;
      else c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % md;
    }
  }
  int r, b;
  scanf("%d %d", &r, &b);
  int ans = r + 1;
  for (int r1 = 1; r1 <= r; r1++) {
    for (int r3 = 0; r1 + r3 <= r; r3++) {
      if (r1 > b - 1) {
        continue;
      }
      int ways = c[b - 1][r1];
      if (r3 > r1 - 1) {
        continue;
      }
      ways = mul(ways, c[r1 - 1][r3]);
      int left = r - r1 - r3;
      ways = mul(ways, c[left + 2][2]);
      add(ans, ways);
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int trials[N];
  for (int i = 0; i < N; i++) {
    trials[i] = 0;
  }
  
  
  for (int i = 1; i <= N; i++) {
    int score = i;
    while (score < K) {
      score = score * 2;
      trials[i-1]++;
    }
  }
  
  double p[N];
  for (int i = 0; i < N; i++) {
    p[i] = 1.0 / N;
  }
  
  double ans = 0.0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < trials[i]; j++) {
      p[i] = p[i] * 0.5;
    }
    ans = ans + p[i];
  }
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>
#include <algorithm>

int main() {
  using namespace std;

  int N;
  cin >> N;

  unordered_map<string, int> m;
  for (int i =0; i<N; i++) {
    string s;
    cin >> s;
    ++m[s];
  }

  vector<pair<string, int>> vec(m.begin(), m.end());

  sort(vec.begin(), vec.end(), [](auto lhs, auto rhs) {
    return (lhs.second == rhs.second) ? (lhs.first < rhs.first) : (lhs.second > rhs.second);
  });

  // cout << "start answer" << endl;
  int maxv = vec[0].second;
  for (auto v : vec) {
    if (v.second != maxv) {
      break;
    }
    // cout << v.first << " " << v.second << endl;
    cout << v.first << endl;
  }
  // cout << "end answer" << endl << endl;

  return 0;
}


Measured memory_bytes: 27272
/*
  || Shree Ganeshay Namah ||

     || Jai Shree Ram ||
  || Nabh Sparsham Diptam ||
*/
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define mod 1000000000000000001
#define block 180
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f1 first
#define s1 second
int jai_shree_ram()
{
    return 1;
}
int shree_ganeshay_namah()
{
    return 1;
}
ll power(ll x,ll y)
{
    ll r=1;
    while(y>0)
    {
        if(y%2!=0)
            r=r*x;
        x=x*x;
        y=y/2;
    }
    return r;
}
ll ncr(ll n,ll k)
{

    ll c[k+1];
    memset(c,0,sizeof(c));
    c[0]=1;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=min(i,k);j>0;j--)
            c[j]=c[j]+c[j-1];
    }
    return c[k];
}

bool prime[500001];
void sieve()
{
    ll i,j;
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(i=2;i<=sqrt(100001);i++)
    {
        if(prime[i])
        {
            for(j=i*i;j<=100001;j=j+i)
                prime[j]=false;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,j,k;
    cin>>n;
    ll f=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            ll x=__gcd(i,j);
            for(k=1;k<=n;k++)
            {
                f=f+__gcd(x,k);
            }
        }
    }
    cout<<f;
    return 0;

}


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

ifstream in ("test.in" );
ofstream out("test.out");

const int EXP = 2e1 + 0;
const int DIM = 2e5 + 5;

int rmq[2][EXP][DIM], aux[DIM], pos[DIM], arr[DIM];

set<pair<int, pair<int, int>>> mst;

int getrmq(int p, int l, int len)
{
    int r = l + len - 1, k = aux[r - l + 1];
    return min(rmq[p][k][l], rmq[p][k][r - (1 << k) + 1]);
}

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n;
    cin >> n;
    
    for (int i = 0; i < (n >> 1); ++i) {
        cin >> rmq[0][0][i] >> rmq[1][0][i];
        
        pos[rmq[0][0][i]] = (i << 1);
        pos[rmq[1][0][i]] = (i << 1 | 1);
        
        arr[i << 1] = rmq[0][0][i];
        arr[i << 1 | 1] = rmq[1][0][i];
    }
    
    for (int i = 2; i <= n; ++i)
        aux[i] = aux[i >> 1] + 1;
    
    for (int p = 0; p <= 1; ++p)
    for (int k = 1; (1 << k) <= (n >> 1); ++k)
    for (int i = 0, j = (1 << k) - 1; j < (n >> 1); ++i, ++j)
        rmq[p][k][i] = min(rmq[p][k - 1][i], rmq[p][k - 1][i + (1 << (k - 1))]);
    
    mst.insert(make_pair(getrmq(0, 0, n >> 1), make_pair(0, n - 1)));
    
    while (!mst.empty()) {
        int p1 = pos[mst.begin() -> first],
            l = (mst.begin() -> second).first,
            r = (mst.begin() -> second).second,
            par = (l & 1);
        
        int p2 = pos[getrmq(par ^ 1, (p1 + 1) >> 1, (r - p1 + 2) >> 1)];
        
        cout << arr[p1] << " " << arr[p2] << " "; mst.erase(mst.begin());
        
        if (l < p1)
            mst.insert(make_pair(getrmq(par, l >> 1, (p1 - l) >> 1), make_pair(l, p1 - 1)));
        if (p2 < r)
            mst.insert(make_pair(getrmq(par, (p2 + 1) >> 1, (r - p2) >> 1), make_pair(p2 + 1, r)));
        if (p1 + 1 < p2 - 1)
            mst.insert(make_pair(getrmq(par ^ 1, (p1 + 1) >> 1, (p2 - p1 - 1) >> 1), make_pair(p1 + 1, p2 - 1)));
    }
    
    return 0;
}


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

using namespace std;
int n, k;
int a[200001];
int main()
{
    //freopen("test.inp","r", stdin);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = k+1; i <= n; i++)
    {
        if (a[i-k] < a[i]) cout <<"Yes";
        else cout <<"No";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4400
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio;
    string s;
    int a,b,x;
    cin>>a>>x;
    cout<<(a%500<=x ? "Yes" : "No")<<'\n';
    
    return(0);
}

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

int main() {
  int n, ans = 0;
  cin >> n;
  int a[n + 1];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += a[i] * a[j];
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    int n;
    cin >> n;
    vector<int> t(n + 1), x(n + 1), y(n + 1);
    t[0] = x[0] = y[0] = 0;
    for (int i = 1; i <= n; i++){
        cin >> t[i] >> x[i] >> y[i];
    }

    bool ans = true;
    for (int i = 0; i < n; i++){
        int dt = t[i + 1] - t[i], dx = abs(x[i + 1] - x[i]), dy = abs(y[i + 1] - y[i]);
        if (dt < dx + dy || dt % 2 != (dx + dy) % 2){
            ans = false;
            break;
        }
    }

    cout << (ans?"Yes":"No") << endl;
    
    return 0;
}

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

int main()
{
    long long n, a, b;
    cin >> n >> a >> b;

    if(a > b || (n == 1 && a != b))
    {
        cout << 0;
        return 0;
    }

    cout << (n - 2)*(b-a) + 1;

}


Measured memory_bytes: 3628
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	int X, A;
	cin >> X >> A;
	cout << (X < A ? 0 : 10) << endl;
	return 0;
}


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

int main(void){
    int N;
    scanf("%d", &N);
    int i, j, k;
    int data[N][3];
    for(i = 0; i < N; i++){for(j = 0; j < 3; j++){scanf("%d", &data[i][j]);}}

    int cx, cy;
    int dx, dy;
    int count;
    int height[N];
    int ans;
    int flag;
    for(cx = 0; cx <= 100; cx++){
        for(cy = 0; cy <= 100; cy++){
            flag = 1;
            k = 0;
            while((data[k][2] == 0) && (k < N)){
                k++;
                if(k == N)break;
            }
            //入力された組のhiが一つでも0を超えていたら
            if(k != N){
                ans = abs(data[k][0]-cx) + abs(data[k][1]-cy) + data[k][2];
                for(i = 0; i < N; i++){
                    int d = abs(data[i][0]-cx) + abs(data[i][1]-cy) + data[i][2];
                    if((data[i][2] > 0) && (ans != d)){flag = 0; break;}
                    if((data[i][2] == 0) && (ans > d)){flag = 0; break;}
                }
                if(flag == 1){printf("%d %d %d\n", cx, cy, ans); return 0;}
            }
            //入力された組みのhiが全て0だったら
            else{
                for(i = 0; i < N; i++){
                    if((data[i][0]!=cx) || (abs(data[i][1]-cy)!=1)){flag = 0; break;}
                    if((abs(data[i][0]-cx)!=1) || (data[i][1]!=cy)){flag = 0; break;}
                }
                if(flag == 1){printf("%d %d %d\n", cx, cy, 1); return 0;}
            }
        }
    }
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define MOD 1000000007
#define mod 998244353
#define inf MOD 
#define sec setprecision
#define Pair pair<ll,ll>
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x) % mod, n / 2) % mod);
	else
		return (x * pow(x, n - 1)) % mod;
}
int main() {
	ll x, y, z, k; cin >> x >> y >> z >> k;
	vector<ll>a(x); rip(i, x)cin >> a[i];
	vector<ll>b(y); rip(i, y)cin >> b[i];
	vector<ll>c(z); rip(i, z)cin >> c[i];
	sort(all(a));
	sort(all(b));
	vector<ll>ans;
	if (x * y * z < 100000) {
		rip(i, x) {
			rip(j, y) {
				rip(s, z) {
					ans.push_back(a[i] + b[j] + c[s]);
				}
			}
		}
		sort(all(ans));
		reverse(all(ans));
		rip(i, k) {
			cout << ans[i] << endl;
		}
	}
	else {
		rip(i, x) {
			rip(j, y)ans.push_back(a[i] + b[j]);
		}
		sort(all(ans));
		reverse(all(ans));
		vector<ll>e(k);
		rip(i, k) {
			e[i] = ans[i];
		}
		vector<ll> kotae;
		rip(i, k) {
			rip(j, z) {
				kotae.push_back(e[i] + c[j]);
			}
		}
		sort(all(kotae));
		reverse(all(kotae));
		rip(i, k)cout << kotae[i] << endl;
	}
}

Measured memory_bytes: 44088
/*
Author: Srinjoy
Language: C++ 17
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define fileinput(s) freopen(s,"r",stdin)
#define MINUS(a) memset(a,0xff,sizeof(a))
typedef long long ll;
const ll mod = 1000000007;

template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }
 
template<class T>
istream& operator >> (istream& in, pair<T, T> & v){ in >> v.fi >> v.se;return in; }

void printArr(vector<int> arr){
	cout<<"\n------------------------------------\n";

	for(int i=0;i<arr.size();i++) cout<<arr[i]<<" ";
	
	cout<<"\n------------------------------------\n";
}

/*

int main(){
    int n,d,a;
    cin>>n>>d>>a;
    vector<pair<int,int>> p(n);
    for(auto& e:p)cin>>e.first>>e.second;
    sort(p.begin(),p.end());
    vector<int> s(n+1);
	int r=0;
    long long ans=0;
    rep(i,n){
        p[i].second-=s[i];
        while(r<n&&p[r].first<=p[i].first+2*d)++r;
        if(p[i].second>0){
            int num=(p[i].second+a-1)/a;
            ans+=num;
            s[i]+=num*a;
            s[r]-=num*a;
        }
        s[i+1]+=s[i];
    }
    cout<<ans<<endl;
    return 0;
}
*/
int main(){
	optimiza_io
	
	int n,d,a;
    cin>>n>>d>>a;
    vector<pair<int,int>> p(n);

    for(auto& e:p)cin>>e.first>>e.second;
   	sort(p.begin(),p.end());
    
    vector<int> s(n+1);

	int r=0;
    
    ll ans=0;


	for(int i=0;i<n;i++){
		p[i].second-=s[i];

        while(r<n&&p[r].first<=p[i].first+2*d)++r;
        if(p[i].second>0){
            int num=(p[i].second+a-1)/a;
            ans+=num;
            s[i]+=num*a;
            s[r]-=num*a;
        }
        
        s[i+1]+=s[i];


	}


	cout<<ans<<endl;


}

Measured memory_bytes: 2560
def resolve():
    N, K = list(map(int, input().split()))
    cnt = 0
    for b in range(1, N+1):
        cnt += (N//b)*max(0,b-K)+max(0, N%b-K+1)
    print(cnt if K != 0 else cnt-N)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define vi vector <int>
#define vl vector <long long>
#define pb push_back
#define mk make_pair
#define pi pair <int,int>
#define pl pair <ll,ll>
#define rep(i,a,n) for(int i=a;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define rep_(i,a,n) for(int i=(n-1);i>=a;i--)
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    map <string,int> m;
    rep(i,0,n)
    {
    	cin>>s;
    	sort(all(s));
    	//cout<<s<<endl;
    	if(m.find(s)==m.end())
    		m.insert(mk(s,1));
    	else
    		m[s]++;
	}
	ll ans=0;
	for(auto i=m.begin();i!=m.end();i++)
	{
		ll x=i->second;
		ans+=(x*(x-1))/2;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11264
s=input()
t=input()
if len(set(t)-set(s))>0:
  print(-1)
  exit()

ss=s*2
ind=-1
ans=0
for c in t:
  nex=ss[ind+1:].find(c)
  ind=(ind+1)+nex
  if ind>=len(s):
    ind-=len(s)
    ans+=len(s)

print(ans+ind+1)


Measured memory_bytes: 3700
import java.util.*;

public class Main {
    static final int COLUMN = 8;
    static final int ROW = 8;
    static final String[] FIG = {"A", "B", "C", "D", "E", "F", "G"};

    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        while (scanner.hasNext()) {
            String[] str = new String[8];
            
            for (int i = 0; i < ROW; i++) {
                str[i] = scanner.next();
            }
            
            int[] figXIdx = new int[4];
            int[] figYIdx = new int[4];
            int cnt = 0;
                    
            for (int i = 0; i < ROW; i++) {
                for (int j = 0; j < COLUMN; j++) {
                    if (str[i].charAt(j) == '1') {
                        figXIdx[cnt] = j;
                        figYIdx[cnt] = i;
                        cnt++;
                    }
                }
            }
            System.out.println(FIG[judgeFig(figXIdx, figYIdx)]);
            scanner.nextLine();
        }            
    }
    
    public static int judgeFig(int[] x, int[] y) {
        
        int x1 = x[0];
        int x2 = x[1];
        int x3 = x[2];
        int x4 = x[3];
        int y1 = y[0];
        int y2 = y[1];
        int y3 = y[2];
        int y4 = y[3];

        if (x1 == x3 && x2 == x4 && y1 == y2 && y3 == y4) {
            return 0;
        } else if (x1 == x2 && x2 == x3 && x3 == x4 && x4 == x1) {
            return 1;
        } else if (y1 == y2 && y2 == y3 && y3 == y4 && y4 == y1) {
            return 2;
        } else if (x1 == x3) {
            return 3;
        } else if (x2 == x3) {
            return 4;
        } else if (x1 == x2) {
            return 5;
        } else {
            return 6;
        }
    }
}

Measured memory_bytes: 20168
import sys


def main(N, matrix):
    row = len(matrix)
    col = len(matrix[0])
    res = []
    for i in range(row):
        res.append([0] * col)
    for action in range(3):
        res[0][action] = matrix[0][action]

    for day in range(1, N):
        for action in range(3):
            res[day][action] = matrix[day][action]
            for prev_action in [a for a in range(3) if a != action]:
                res[day][action] = max(res[day][action], res[day-1][prev_action] + matrix[day][action])

    print max(res[N - 1])


if __name__ == '__main__':
  N, matrix = None, []
  matrix = []
  for i, line_ in enumerate(sys.stdin):
    line = line_.strip()
    if line:
        if not i:
            N = int(line.strip())
        else:
            H = map(int, line.strip().split())
            matrix.append(H)
  if N is not None and matrix:
    main(N, matrix)


Measured memory_bytes: 42228
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll d4[]={-1,0,1,0,-1};
ll x[210];
ll y[210];
int main(){
	ll n;
	while(scanf("%lld",&n),n){
		ll mx=0,Mx=0,my=0,My=0;
		rep(i,1,n){
			ll k,d;
			scanf("%lld%lld",&k,&d);
			x[i]=x[k]+d4[d];
			y[i]=y[k]+d4[d+1];
			mx=min(mx,x[i]);
			Mx=max(Mx,x[i]);
			my=min(my,y[i]);
			My=max(My,y[i]);
		}
		printf("%lld %lld\n",Mx-mx+1,My-my+1);
	}
}


Measured memory_bytes: 2040
#include<stdio.h>
int main(void)
{
    int n;
    scanf("%d",&n);
    switch(n){
        case 1:
            printf("1\n");
            break;
        case 2:
            printf("2\n");
            break;
        case 3:
            printf("6\n");
            break;
        case 4:
            printf("24\n");
            break;
        case 5:
            printf("120\n");
            break;
        case 6:
            printf("720\n");
            break;
        case 7:
            printf("5040\n");
            break;
        case 8:
            printf("40320\n");
            break;
        case 9:
            printf("362880\n");
            break;
        case 10:
            printf("3628800\n");
            break;
        case 11:
            printf("39916800\n");
            break;
        case 12:
            printf("479001600\n");
            break;
        case 13:
            printf("6227020800\n");
            break;
        case 14:
            printf("87178291200\n");
            break;
        case 15:
            printf("1307674368000\n");
            break;
        case 16:
            printf("20922789888000\n");
            break;
        case 17:
            printf("355687428096000\n");
            break;
        case 18:
            printf("6402373705728000\n");
            break;
        case 19:
            printf("121645100408832000\n");
            break;
        case 20:
            printf("2432902008176640000\n");
            break;
    }

    return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[1010][1010];
ll dis[1010][1010];
bool f[1010][1010];
int main(){
	ll h,w,sy,sx,gy,gx;
	cin>>h>>w>>sy>>sx>>gy>>gx;
	for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){
		cin>>s[i][j];
		dis[i][j]=1e9;
	}
	dis[sy][sx]=0;
	deque<pair<pair<ll,ll>,ll>>deq;
	deq.push_front({{sy,sx},0});
	ll dy[4]={0,1,0,-1},dx[4]={1,0,-1,0};
	while(!deq.empty()){
		pair<pair<ll,ll>,ll>p=deq.front();
		deq.pop_front();
		ll y=p.first.first,x=p.first.second,cos=p.second;
		if(f[y][x])continue;
		f[y][x]=1;
		for(int i=0;i<4;i++){
			if(!(1<=y+dy[i]&&y+dy[i]<=h&&1<=x+dx[i]&&x+dx[i]<=w))continue;
			if(s[y+dy[i]][x+dx[i]]=='.'){
				if(cos<dis[y+dy[i]][x+dx[i]]){
					deq.push_front({{y+dy[i],x+dx[i]},cos});
					dis[y+dy[i]][x+dx[i]]=cos;
				}
			}
		}
		for(int j=y-2;j<=y+2;j++){
			for(int k=x-2;k<=x+2;k++){
				if(!(1<=j&&j<=h&&1<=k&&k<=w)||(j==y&&k==x))continue;
				if(s[j][k]=='.'&&cos+1<dis[j][k]){
					deq.push_back({{j,k},cos+1});
					dis[j][k]=cos+1;
				}
			}
		}
	}
	if(dis[gy][gx]==1e9)cout<<-1<<endl;
	else cout<<dis[gy][gx]<<endl;
	return 0;
}


Measured memory_bytes: 13668
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
4
2 2 1 3
'''

def solve(l):
	n = len(l)
	l.sort(reverse=True)
	ans = 0
	ans = 0
	hp = [[-l[0],-l[0]]]
	for i in range(1,n):
		curr = l[i]
		p = heappop(hp)
		minn = max(p)
		ans -= minn
		ll = [max(p),-curr]
		ll.sort(reverse=True)
		heappush(hp,ll)
		ll = [min(p),-curr]
		ll.sort(reverse=True)
		heappush(hp,ll)
	return ans
	

N = int(stdin.readline())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)
print(ans)



Measured memory_bytes: 140884
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
#define all(a) sort((a).begin(),(a).end()) 
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==v.size()?"":" ");
    return os;
}


signed main(){
    int n;cin>>n;
    string s;cin>>s;
    string t=s;
  	all(t);
  
    int c=0;
    rep(i,n)if(s[i]!=t[i])c++;
    cout<<(c/2)<<endl;
    return 0;
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string s;
	unsigned long long int k;
	cin >> s >> k;
	int count = 0;
	for (int i = 0; i < 100; ++i)
	{
		if (s[i] - '0' == 1)
		{
			++count;
		}
		if (s[i] != '1')
		{
			break;
		}
	}
	if (count >= k)
	{
		cout << 1 << endl;
	}
	else
	{
		cout << s[count] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main(int argv, char** argc) {
      int N;
      int TP[100010][3];
      bool flag=false;
      cin >> N;
      TP[0][0]=0;
      TP[0][1]=0;
      TP[0][2]=0;
      for(int i=1;i<N+1;i++){
        cin >> TP[i][0];
        cin >> TP[i][1];
        cin >> TP[i][2];
      }
     
      for(int i=1;i<N+1;i++){
        if((TP[i][0]-TP[i-1][0])-(abs(TP[i][1]-TP[i-1][1])+abs(TP[i][2]-TP[i-1][2]))>-1
           &&((TP[i][0]-TP[i-1][0])-(abs(TP[i][1]-TP[i-1][1])+abs(TP[i][2]-TP[i-1][2])))%2==0)
          flag=true;
        else
          flag=false;
      }
      if(true==flag)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
      return 0;
    }

Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n, k; cin >> n >> k;
  vector<ll> x(n); rep(i, n) cin >> x[i];
  int t = distance(x.begin(), lower_bound(all(x), 0));

  ll ans = 0xffffffff;
  for (int a = 1; a < k; a++) {
    int b = k - a;
    int li = t-(a-1);
    int ri = t+b;
    if (li >= 0 && ri < n) {
      ans = min({
        ans,
        2*abs(x[li]) + abs(x[ri]),
        abs(x[li]) + 2*abs(x[ri])
      });
    }
  }
  if (t+k-1 < n) ans = min(ans, abs(x[t+k-1]));
  if (t-k >= 0)  ans = min(ans, abs(x[t-k]));
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

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

#define MAX_BIN 17
/*
bitset<MAX_BIN> crop(bitset<MAX_BIN> num, int a){
    for(int i=a;i<MAX_BIN-1;i++){
        num[i]=num[i+1];
    }
    num[MAX_BIN-1]=0;
    return num;
}
*/
bitset<MAX_BIN> crop(bitset<MAX_BIN> num, int a){
    unsigned long long int nn=num.to_ullong();
    unsigned long long int downmask=(1<<a)-1;
    unsigned long long int upmask=((1<<MAX_BIN)-1)^((1<<(a+1))-1);
    unsigned long long int ans=(nn&downmask)+((nn&upmask)>>1);
    bitset<MAX_BIN> aa(ans);
    return aa;
}
/*
bitset<MAX_BIN> insert(bitset<MAX_BIN> num, int bit,int a){
    for(int i=MAX_BIN-1;i>=a+1;i--){
        num[i]=num[i-1];
    }
    num[a]=bit;
    return num;
}*/
bitset<MAX_BIN> insert(bitset<MAX_BIN> num, int bit,int a){
    unsigned long long int nn=num.to_ullong();
    unsigned long long int downmask=(1<<a)-1;
    unsigned long long int upmask=((1<<MAX_BIN)-1)^((1<<a)-1);
    unsigned long long int ans=(nn&downmask)+((nn&upmask)<<1)+(bit<<a);
    bitset<MAX_BIN> aa(ans);
    return aa;
}

vector<bitset<MAX_BIN>> GrayCodeGenerator(bitset<MAX_BIN> a,bitset<MAX_BIN> b,int binary_digit){
    //printf("###hoge [%ld:%ld]\n",a.to_ulong(),b.to_ulong());
    if(binary_digit==1){
        vector<bitset<MAX_BIN>> ans;
        ans.push_back(a);
        ans.push_back(b);
        return ans;
    }
    int dig;
    for(int i=binary_digit-1;i>=0;i--){
        if(a[i]!=b[i])dig=i;
    }
    //printf("%d\n",dig);
    bitset<MAX_BIN> adash=crop(a,dig);
    bitset<MAX_BIN> bdash=crop(b,dig);
    //printf("%lld %lld\n",a.to_ullong(),adash.to_ullong());
    bitset<MAX_BIN> c=adash;
    c=c.flip(binary_digit-2);
    vector<bitset<MAX_BIN>> p=GrayCodeGenerator(adash,c,binary_digit-1);
    vector<bitset<MAX_BIN>> q=GrayCodeGenerator(c,bdash,binary_digit-1);
    REP(i,p.size())p[i]=insert(p[i],a[dig],dig);
    REP(i,q.size())q[i]=insert(q[i],b[dig],dig);
    std::copy(q.begin(),q.end(),std::back_inserter(p));
    return p;
}

int main()
{
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    std::bitset<17> aa(a);
    std::bitset<17> bb(b);
    std::bitset<17> dif=aa^bb;
    if(dif.count()%2==0){
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
    vector<bitset<MAX_BIN>> ans=GrayCodeGenerator(aa,bb,n);
    for(bitset<MAX_BIN> i : ans){
        printf("%lld\n",i.to_ullong());
    }
    return 0;
}

Measured memory_bytes: 2288
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> cnt(4);
  vector<string> S(n);
  rep(i, n) {
    cin >> S[i];
    if(S[i] == "AC") cnt[0]++;
    else if(S[i] == "WA") cnt[1]++;
    else if(S[i] == "TLE") cnt[2]++;
    else cnt[3]++;
  }
  cout << "AC x " << cnt[0] << "\n";
  cout << "WA x " << cnt[1] << "\n";
  cout << "TLE x " << cnt[2] << "\n";
  cout << "RE x " << cnt[3] << "\n";
  return 0;
}


Measured memory_bytes: 6344
#include<stdio.h>

int main()
{
    int a,x1,x2,x3,x4,x5;
    scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
    if(x1 == 0)
    {
      printf("1\n");
    }
    if(x2 == 0)
    {
      printf("2\n");
    }
    if(x3 == 0)
    {
      printf("3\n");
    }
    if(x4 == 0)
    {
      printf("4\n");
    }
    if(x5 == 0)
    {
      printf("5\n");
    } 
    return 0;
}

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

# https://qiita.com/LorseKudos/items/9eb560494862c8b4eb56
divisors = []
for i in range(1, int(N ** 0.5) + 1):
    if N % i == 0:
        divisors.append(i)
        if i != N // i:
            divisors.append(N // i)

ans = 0
for d in divisors:
    if N // d < d - 1:
        ans += d - 1
print(ans)


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

int main(){
    int n;
    while(true){
        cin >> n;
        if(n == 0){
            break;
        }

        int dice[6] = {1, 6, 2, 5, 4, 3};
        int ans = 1;
        string s;
        for(int i=0; i<n; i++){
            cin >> s;
            int tmp;
            if(s == "North"){
                tmp = dice[0];
                dice[0] = dice[2];
                dice[2] = dice[1];
                dice[1] = dice[3];
                dice[3] = tmp;
            }else if(s == "East"){
                tmp = dice[0];
                dice[0] = dice[4];
                dice[4] = dice[1];
                dice[1] = dice[5];
                dice[5] = tmp;
            }else if(s == "West"){
                tmp = dice[0];
                dice[0] = dice[5];
                dice[5] = dice[1];
                dice[1] = dice[4];
                dice[4] = tmp;
            }else if(s == "South"){
                tmp = dice[0];
                dice[0] = dice[3];
                dice[3] = dice[1];
                dice[1] = dice[2];
                dice[2] = tmp;
            }else if(s == "Right"){
                tmp = dice[2];
                dice[2] = dice[5];
                dice[5] = dice[3];
                dice[3] = dice[4];
                dice[4] = tmp;
            }else if(s == "Left"){
                tmp = dice[2];
                dice[2] = dice[4];
                dice[4] = dice[3];
                dice[3] = dice[5];
                dice[5] = tmp;
            }
            ans += dice[0];
        }
        cout << ans << endl;
    }
  
  return 0;
}

Measured memory_bytes: 3056
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

typedef long long ll;

int N;
ll A[200000 + 10], B[200000 + 10];

int bef(int i) {
	if (i == 0)return N - 1;
	else return i - 1;
}

int nxt(int i) {
	if (i == N - 1)return 0;
	else return i + 1;
}

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

	queue<int> q;
	ll cnt = 0;
	for (int i = 0; i < N; i++) {
		if (B[i] > B[bef(i)] + B[nxt(i)] && B[i] != A[i])q.push(i);
	}
	while (q.size()) {
		int pos = q.front(); q.pop();

		if (((B[pos] - A[pos]) % (B[bef(pos)] + B[nxt(pos)]) == 0)) {
			cnt += ((B[pos] - A[pos]) / (B[bef(pos)] + B[nxt(pos)]));
			B[pos] = A[pos];
		}
		else {
			cnt += B[pos] / (B[bef(pos)] + B[nxt(pos)]);
			B[pos] %= (B[bef(pos)] + B[nxt(pos)]);
			if (A[pos] > B[pos]) {
				cout << -1 << endl;
				return 0;
			}
		}
		if (B[bef(pos)] > B[pos] + B[bef(bef(pos))] && B[bef(pos)] != A[bef(pos)])q.push(bef(pos));
		if (B[nxt(pos)] > B[pos] + B[nxt(nxt(pos))] && B[nxt(pos)] != A[nxt(pos)])q.push(nxt(pos));
	}
	for (int i = 0; i < N; i++) {
		if (A[i] != B[i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3840
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------


int main(){
  int N;
  double sum = 0;
  cin >> N;
  vector<double> x(N),y(N);
  for(int i=0; i<N; i++){
    cin >> x[i] >> y[i];
  }
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    vec[i] = i;
  }
  do{
    double res = 0;
    for(int i=1; i<N; i++){
      res += pow((x[vec[i]]-x[vec[i-1]])*(x[vec[i]]-x[vec[i-1]])+(y[vec[i]]-y[vec[i-1]])*(y[vec[i]]-y[vec[i-1]]),0.5);
    }
    sum += res;
  }while(next_permutation(vec.begin(),vec.end()));
  double res = 1;
  for(int i=1; i<=N; i++){
    res *= i;
  }
  sum /= res;
  cout << fixed << setprecision(10) << sum << endl;
  return 0;
}


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

int main() {
  int A;
  cin >> A;
  string S[A];
  int check=0;
  for(int i=0;i<A;i++){
    cin >> S[i];
  }
  for(int i=0;i<A;i++){
    if(S[i]=="Y"){
      cout<<"Four"<<endl;
      check=1;
      break;
    }
  }
  if(check==0) cout<<"Three"<<endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

#define MAX_V 10010
struct edge {int to;long long cap;int rev;};
vector<edge> G[MAX_V];	// 最大フロー用の隣接リスト
bool used[MAX_V];
void add_edge(int from,int to,long long cap) {
	G[from].push_back((edge){to,cap,(int)G[to].size()});
	G[to].push_back((edge){from,0,(int)G[from].size()-1});
}
long long dfs(int v,int t,long long f) {
	if(v==t) return f;
	used[v]=true;
	for(int i=0; i<G[v].size(); ++i) {
		edge &e=G[v][i];
		if(!used[e.to]&&e.cap>0) {
			long long d=dfs(e.to,t,min(f,e.cap));
			if(d>0) {
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
long long FordFulkerson(int s,int t, vector<vector<P>>& adj) {
	// adj は通常の隣接リスト（first: to, second: cost）
	for(int i=0; i<(int)adj.size(); i++) {
		for(int j=0; j<(int)adj[i].size(); j++) {
			add_edge(i,adj[i][j].first,adj[i][j].second);
		}
	}
	long long flow=0;
	while(1) {
		for(int i=0; i<MAX_V; ++i) used[i]=false;
		long long f=dfs(s,t,INF*INF);
		if(f==0) return flow;
		flow+=f;
	}
}

int main() {
	ios::sync_with_stdio(false);
	ll h,w;
	cin>>h>>w;
	vector<vector<char>> a(h,vector<char>(w));
	REP(i,h) REP(j,w) cin>>a[i][j];
	vector<vector<P>> adj(h+w);
	P s=P(0,0),t=P(0,0);
	REP(i,h) REP(j,w) {
		if(a[i][j]=='o') {
			adj[i].pb(P(h+j,1));
			adj[h+j].pb(P(i,1));
		}
		if(a[i][j]=='S') {
			adj[i].pb(P(h+j,INF));
			adj[h+j].pb(P(i,INF));
			s=P(i,j);
		}
		if(a[i][j]=='T') {
			adj[i].pb(P(h+j,INF));
			adj[h+j].pb(P(i,INF));
			t=P(i,j);
		}
	}
	if(s.first==t.first||s.second==t.second) cout<<-1<<endl;
	else cout<<FordFulkerson(s.first,t.first,adj)<<endl;
}


Measured memory_bytes: 2176
N,K = map(int,input().split())
V = list(map(int,input().split()))
M = min(N,K)
ans = 0

for i in range(M+1):
  for j in range(M-i+1):
    G = V[:i]+V[N-j:]
    G.sort()
    for j in range(K-i-j+1):
      ans = max(ans,sum(G[j:]))

print(ans)

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

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> v(n);
        for (auto& i : v) cin >> i;
        sort(v.begin(), v.end());

        int min_sub = 1 << 28;

        for (int i = 0; i < n - 1; i++) {
            min_sub = min(min_sub, v[i+1]-v[i]);
        }

        cout << min_sub << endl;
    }

    return 0;
}

Measured memory_bytes: 3024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define vi vector<int>

using ll = long long;
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
inline ll inv(ll x, ll div){return pow(x, div - 2, div);}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  ll n,a,b; cin >> n >> a >> b;
  cout << n/(a+b)*a + min(a, n % (a+b)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll a,b,c;cin>>a>>b>>c;
    out((a+1)/2);
}

Measured memory_bytes: 256
//in the name of GOD//

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie();
#define sz(s) s.size()

int main(){
  string s;
  cin >> s;
  for(int i = 0; i < 4; i++){
    cout << s[i];
  }
  cout << ' ';
  for(int i = 4; i < 12; i++){
    cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;

int main() {
    int A,B,C;cin>>A>>B>>C;
    ll ans = 0;
    while(true){
        if(A&1 || B&1 || C&1) break;
        int ta = B/2 + C/2;
        int tb = A/2 + C/2;
        int tc = A/2 + B/2;
        A = ta;
        B = tb;
        C = tc;
        ++ans;
        if(A==B && B==C){
            cout << -1 << '\n';
            return 0;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256