akhauriyash/Code-Regression huggingface dataset:
n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
'''
ここは任意
'''

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for i in range(n+1):
    tmp = n -i -1
    if n-i < k:
        continue
    kei = cmb(tmp,k-1,mod)
    ans += A[tmp] * kei % mod
    ans -= A[i] * kei %mod
print(ans % mod)
    

Measured memory_bytes: 76968
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n, m;
    while(cin >> n >> m, n||m){
        vector<int> v;
        v.pb(0);
        rep(i,n + m){
            int inp;
            cin >> inp;
            v.pb(inp);
        }
        sort(all(v));
        int longer = 0;
        rep(i,v.size() - 1){
            longer = max(longer, v[i + 1] - v[i]);
        }
        cout << longer << endl;
    }
}

Measured memory_bytes: 1348
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

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


int main()
{
  int N, L;
  cin >> N >> L;
  vector<int> v;

  int sum = 0;
  REP(i, N) {
    v.PB(L + i);
    sum += v[i];
  }

  int ans = INF;
  REP(i, N) {
    int tmp = sum - v[i];
    if (abs(tmp - sum) < abs(ans - sum)) {
      ans = tmp;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    int len=s.size();
    for(int i=0;i<=len;i++)
    {
        if(s[i]=='C') 
        {
            for(int j=i;j<=len;j++)
            {
                if(s[j]=='F') 
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;//没有C和F 输出 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	if (n == 1)
	{
		cout << "Hello World" << endl;
	}
	else
	{
		int a, b;
		cin >> a >> b;
		printf("%d\n", a + b);
	}
	return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,a;
    cin >> n >> a;
    const int M=2500;
    vector<vector<ll>> dp(n+1,vector<ll>(M+1,0));
    dp[0][0]=1;
    for(int o=0;o<n;o++)
    {
        int x;
        cin >> x;
        for(int i=n-1;i>=0;i--)
        {
            for(int j=0;j+x<=M;j++) dp[i+1][j+x]+=dp[i][j];
        }
    }
    ll res=0;
    for(int i=1;i<=n;i++) res+=dp[i][a*i];
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>

int main() {
  int S, h, m, s;
  std::cin >> S;
  s = S % 60;
  m = S / 60 % 60;
  h = S / 3600;

  // printf("%02d:%02d:%02d", h, m, s);
  printf("%d:%d:%d\n", h, m, s);
}


Measured memory_bytes: 3228
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		// 計算
		long result = 0;
		long MOD = 1000000007L;
		for(long i = k; i <= n+1; i++){
		    result += i*(2*n+1-i)/2 - (i-1)*i/2 + 1;
		    result %= MOD;
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 27232
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	ll N, K; cin >> N >> K;
	if (K < N) {
		N = K + (N - K) % K;
		N -= K;
	}
	cout << min(N, K - N) << endl;
	return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)

typedef long long lint;

const lint MOD = (lint)1e8 + 7;
lint pascal[1010][1010];

int main() {
	pascal[0][0] = 1;
	
	for_(i,1,1010) {
		pascal[i][0] = pascal[i][i] = 1;
		for_(j,1,i) pascal[i][j] = (pascal[i - 1][j] + pascal[i - 1][j - 1]) % MOD;
	}
	
	int r, c, sy, sx, gy, gx;
	cin >> r >> c >> sy >> sx >> gy >> gx;
	
	int t = 1;
	if (r == abs(gy - sy) * 2) t *= 2;
	if (c == abs(gx - sx) * 2) t *= 2;
	
	int yy = min(abs(gy - sy), r - abs(gy - sy));
	int xx = min(abs(gx - sx), c - abs(gx - sx));
	
	cout << (pascal[xx+yy][xx] * t) % MOD << endl;
	
	return 0;
}

Measured memory_bytes: 8380
n, y = map(int, input().split())
for i in range(n + 1):
    if 10000*i > y:
        break
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 3060
#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 N;
string s;
void dfs(string s,char tmp){
  if(s.size()==N){
    cout << s << endl;
    return;
  }
  for (char c='a';c<=tmp+1;c++){
    string t = s;
    t+=c;
    dfs(t,max(c,tmp));
  }
  return;
}

int main(){
  cin >> N;
  dfs("",'a'-1);
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

int bfs(const vector<vector<int>> &g, int s, int t)
{
	const int N = g.size();
	vector<int> best(N, 1 << 30);

	best[s] = 0;

	queue<int> q;
	q.push(s);
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		for (auto y : g[x]) {
			if (best[x] + 1 < best[y]) {
				best[y] = best[x] + 1;
				q.push(y);
			}
		}
	}
	return best[t];
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>> g0(N);

	for (int i = 0; i < M; ++i) {
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		g0[u].push_back(v);
	}
	int S, T;
	cin >> S >> T;
	--S;
	--T;

	vector<vector<int>> g(3 * N);

	for (int i = 0; i < N; ++i) {
		for (auto j : g0[i]) {
			g[3 * i + 0].push_back(3 * j + 1);
			g[3 * i + 1].push_back(3 * j + 2);
			g[3 * i + 2].push_back(3 * j + 0);
		}
	}
	int ans = bfs(g, 3 * S, 3 * T);
	if (ans == (1 << 30)) {
		cout << -1 << endl;
	}
	else {
		cout << ans / 3 << endl;
	}
}


Measured memory_bytes: 23296
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a;
    cin>>n;
    map<int, int> mp;
    while(n--){
        cin>>a;
        if(mp[a]){
            cout<<"NO\n";
            return 0;
        }
        mp[a]++;
    }
    cout<<"YES\n";
}


Measured memory_bytes: 9600
n = int(input())
a = list(map(int, input().split()))

st = set(a)
lst = list(st)

if n == 3 and a[0] ^ a[1] == a[2]:
  print("Yes")
elif n  >= 4 and st == {0}:
  print("Yes")
elif n % 3 == 0 and len(st) == 2 and a.count(0) == n /3:
  print("Yes")
elif n % 3 == 0 and len(st) == 3 and lst[0] ^ lst[1] == lst[2] and a.count(lst[0]) == n /3 and a.count(lst[1]) == n/3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 14116
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);
        int x;

        x = sc.nextInt();

        if(x < 1200) {
            out.println("ABC");
        } else {
            out.println("ARC");
        }

        sc.close();
    }
}

Measured memory_bytes: 22740
fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    if (n == 0) {
        println(0)
        return
    }
    val bin = arrayListOf<Char>()
    var i = 1
    while (n != 0) {
        if (n % 2 == 0) {
            bin += '0'
            n /= 2
        } else {
            bin += '1'
            n = (n + if (i % 2 == 0) 1 else -1) / 2
        }
        i++
    }
    bin.reversed().forEach(::print)
    println()
}


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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 5e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int n, q;
char s[maxn];

struct SegmentTree{
  int n;
  vector<int> f;
  SegmentTree(int _n = 0) : f(_n * 4, 0), n(_n) {}
  #define Left id * 2
  #define Right id * 2 + 1
  void Update(int l, int r, int id, int i, int c){
    if (l > i || r < i) return;
    if (l == i && r == i){
      f[id] = (1 << c);
      return;
    }
    int mid = (l + r) / 2;
    Update(l, mid, Left, i, c); Update(mid + 1, r, Right, i, c);
    f[id] = f[Left] | f[Right];
  }

  int Get(int l, int r, int id, int u, int v){
    if (r < u || l > v) return 0;
    if (u <= l && r <= v) return f[id];
    int mid = (l + r) / 2;
    return Get(l, mid, Left, u, v) | Get(mid + 1, r, Right, u, v);
  }

};

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);
//  freopen(Task".out", "w", stdout);
  cin >> n;
  cin >> s + 1;
  SegmentTree sg(n);
  for (int i = 1; i <= n; ++i){
    int c = s[i] - 'a';
    sg.Update(1, n, 1, i, c);
  }
  cin >> q;
  while (q--){
    int t; cin >> t;
    switch (t){
      case 1: {
        int i; char c;
        cin >> i >> c;
        sg.Update(1, n, 1, i, c - 'a');
        break;
      }
      case 2: {
        int l, r;
        cin >> l >> r;
        int cur = sg.Get(1, n, 1, l, r);
        cout << __builtin_popcount(cur) <<'\n';
        break;
      }
    }
  }
}



Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	vector<int> cnt(26);
	rep(i,s.size()){
		cnt.at(s.at(i) - 'a')++;
	}
	bool ok = true;
	rep(i,26) if(cnt.at(i) % 2 == 1) ok = false;
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define each(e,v) for(auto&& e:(v))
#define DEBUG(x) cout<<#x<<": "<<x<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;

int main() {
    int n, k, x, y; cin >> n >> k >> x >> y;
    int sum = 0;
    rep(i, n) {
        if(i < k) sum += x;
        else sum += y;
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std;

int n;
string str;
typedef unsigned long long ull;

int main() {
	while(cin >> n, n)
	{
		char dice[7] = {0, 1, 2, 3, 4, 5, 6};
		ull sum = 1;
		for(int i=0; i<n; i++)
		{
			char t;
			cin >> str;
			if(!str.compare("North"))
			{
				t = dice[1];
				dice[1] = dice[2];
				dice[2] = dice[6];
				dice[6] = dice[5];
				dice[5] = t;
			}

			else if(!str.compare("East"))
			{
				t = dice[4];
				dice[4] = dice[6];
				dice[6] = dice[3];
				dice[3] = dice[1];
				dice[1] = t;
			}

			else if(!str.compare("West"))
			{
				t = dice[1];
				dice[1] = dice[3];
				dice[3] = dice[6];
				dice[6] = dice[4];
				dice[4] = t;
			}

			else if(!str.compare("South"))
			{
				t = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[6];
				dice[6] = dice[2];
				dice[2] = t;
			}

			else if(!str.compare("Right"))
			{
				t = dice[2];
				dice[2] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[4];
				dice[4] = t;
			}

			else if(!str.compare("Left"))
			{
				t = dice[2];
				dice[2] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[3];
				dice[3] = t;
			}

			sum += (ull)dice[1];
		}

		printf("%llu\n", sum);
	}
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(std::string b){
    if(b == "A") cout << "T" << endl;
    if(b == "C") cout << "G" << endl;
    if(b == "G") cout << "C" << endl;
    if(b == "T") cout << "A" << endl;
}

int main(){
    std::string b;
    std::cin >> b;
    solve(b);
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  if (S.at(0)==S.at(1) && S.at(1)==S.at(2)) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int A =1;
  for (int i=0; i<N; i++){
    if (A<K){
      A*=2;
    }
    else{
      A+=K;
    }
  }
  cout << A << endl;
  
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> ll = new ArrayList<>();
        for(int i = 0; i < n; i++){
            ll.add(sc.nextInt());
        }
        Collections.sort(ll);
        long ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                int res = beamSearch(ll,ll.get(j)+ll.get(i));
                ans += Math.max(0,res-j);
            }
        }
        System.out.println(ans);
    }
    
    public static int beamSearch(ArrayList<Integer> ll, int k){
        int left = -1;
        int right = ll.size();
        while(right - left > 1){
            int mid = (right + left) / 2;
            if(ll.get(mid) >= k){
                right = mid;
            }else{
                left = mid;
            }
        }
        return left;
    }
}


Measured memory_bytes: 26220
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<utility>
using namespace std;

template<typename T>
class UnionFind {
    std::map<T, T> parent;
    std::map<T, int> rank;
public:
    void unionSet(const T& a, const T& b) {
        T x = findSet(a), y = findSet(b);
        if(rank[x] < rank[y]) std::swap(x, y);
        parent[y] = x;
        if(rank[x] == rank[y]) rank[x] += 1;
    }
    const T findSet(const T& x) {
        if(!parent.count(x)) {
            rank[x] = 1;
            return parent[x] = x;
        }
        return (parent[x] == x) ? x : (parent[x] = findSet(parent[x]));
    }
};

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> indegree(26);
        vector<int> outdegree(26);
        UnionFind<int> group;
        set<int> root;
        for(int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            int head = s[0] - 'a';
            int tail = s[s.size() - 1] - 'a';
            ++indegree[head];
            ++outdegree[tail];
            group.unionSet(head, tail);
        }
        for(int i = 0; i < 26; ++i) if(indegree[i] != 0 || outdegree[i] != 0) root.insert(group.findSet(i));
        bool ok = true;
        for(int i = 0; i < 26; ++i) if(indegree[i] != outdegree[i]) ok = false;
        if(root.size() != 1) ok = false;
        if(ok) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
}

Measured memory_bytes: 1204
S = input()
count = True
for i,s in enumerate(S):
    if i%2 == 0:
        if s != 'R' and s != 'U' and s != 'D':
            count = False
            break
    if i%2 != 0:
        if s != 'L' and s != 'U' and s != 'D':
            count = False
            break
            
if count == False:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll a[50],b[50];
	for(ll i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	ll ans=0;
	map<pair<ll,ll>,ll>c;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			if(i==j){
				continue;
			}
			ll dx=a[i]-a[j];
			ll dy=b[i]-b[j];
			c[make_pair(dx,dy)]++;
			ans=max(ans,c[make_pair(dx,dy)]);
		}
	}
	cout << n-ans;
	// your code goes here
	return 0;
}

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

int main(){
int n,a=0;cin>>n;
vector<string> g(n),g2(n);r(i,n)cin>>g[i];
r(i,n){
r(j,n)g2[(j+i)%n]=g[j];
int f=1;
r(p,n){r(q,p){if(g2[p][q]!=g2[q][p]){f=0;}}}
if(f)a+=n;
}
cout<<a<<endl;return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

vector<int> G[5001];
bool used[5001]; int ans;
void dfs(int id, int fr) {
	bool f = false;
	rep(j, G[id].size()) {
		int to = G[id][j];
		dfs(to, id);
		if (!used[to]) {
			f = true;
		}
	}
	if (f) {
		used[id] = true; ans++;
	}

}
void solve() {
	int n;
	cin >> n;
	rep1(i, n) {
		int p; cin >> p;
		G[p].push_back(i);
		fill(used, used + n + 1, false);
		ans = 0;
		dfs(0, -1);
		//cout << "ans is ";
		cout << ans << endl;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n>>h>>m>>s,n)solve();
	solve();
	//stop
	return 0;
}



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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<>());
  int slen = s.size();
  int tlen = t.size();
  for (int i = 0; i < min(slen, tlen); ++i) {
    if (s[i] == t[i]) continue;
    cout << (s[i] < t[i] ? "Yes\n" : "No\n");
    return 0;
  }
  if (slen < tlen) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  int K; cin>>K;
  ll ans = 0;
  for(int i=1;i<=K;++i){
    for(int j=1;j<=K;++j){
      for(int k=1;k<=K;++k){
        ans += gcd(gcd(i,j),k);
      }
    }
  }
  cout << ans <<"\n";
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    int sum=0;
    for(int i=0;i<s.size();i++){
        sum += s[i] - '0';
    }
    if(sum % 9 == 0){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,k;cin>>n>>k;
	ll m = (n*(n-1))/2 - k;
	if(m<n-1){
		cout<<-1<<endl;
		return 0;
	}
	vector<pii> ans;
	For(i,0,n){
		For(j,i+1,n){
			if(m>0){
				ans.pb({i,j});
				m--;
			}
		}
	}
	// assert(m==ans.size());
	cout<<ans.size()<<endl;
	for(pii x:ans){
		cout<<x.fi+1<<" "<<x.se+1<<endl;
	}










	
}

Measured memory_bytes: 512
/*input
8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310
*/
#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;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
pii arr[8];
int main(){
    int n;
    cin>>n;
    vector<int> v;
    REP(i,n) cin>>arr[i].f>>arr[i].s,v.pb(i);
    ld ans=0,cnt=0;
    do{
        REP1(i,n-1) ans+=hypot(arr[v[i]].f-arr[v[i-1]].f,arr[v[i]].s-arr[v[i-1]].s);
        ++cnt;
    }while(next_permutation(ALL(v)));
    cout<<fixed<<setprecision(6)<<ans/cnt<<'\n';
}

Measured memory_bytes: 256
n,m = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)
cnt =0
goukei = sum(a)
for i in range(m):
    if a[i] < (1/(4*m) * goukei):
        continue
    else:
        cnt+=1
if cnt == m:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 38384
#include <stdio.h>
#include <string.h>

int main(){
  char A[20] = {}, B[20] = {}, C[20] = {};
  scanf("%s%s%s", A, B, C);
  if(A[strlen(A)-1] == B[0] && B[strlen(B)-1] == C[0]){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll L,a,b,mod;
struct Matric
{
    ll a[3][3];
    Matric(){memset(a,0,sizeof(a));}
    Matric operator*(const Matric&o)const
    {
        Matric ans;
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
            ans.a[i][j]=(ans.a[i][j]+a[i][k]*o.a[k][j]%mod)%mod;
        return ans;
    }
};
Matric Mqpow(Matric a,ll n)
{
    Matric ans;
    ans.a[0][0]=ans.a[1][1]=ans.a[2][2]=1;
    while(n)
    {
        if(n&1) ans=ans*a;
        a=a*a;
        n>>=1;
    }
    return ans;
}
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int getlen(ll x)
{
    int ans=0;
    while(x)
    {
        x/=10;
        ans++;
    }
    return ans;
}
ll getpos(int x)
{
    ll l=1,r=L,ans=1;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(getlen(a+(m-1)*b)<=x) ans=m,l=m+1;
        else r=m-1;
    }
    return ans;
}
/*
si=s(i-1)*qpow(10,i)+qi+B;
gi=g(i-1)+B;
|10i 1 1| |si-1|
|0   1 1| |gi-1|
|0   0 1| |B|
*/
int main()
{
    scanf("%lld%lld%lld%lld",&L,&a,&b,&mod);
    //mod=1e9+7;
    ll ans=a%mod,res=a%mod,now=1;
    for(int i=1;i<=18;i++)
    {
        ll p=getpos(i);
        if(p==now) continue;
        Matric A;
        A.a[0][0]=qpow(10,i);A.a[0][1]=0;A.a[0][2]=0;
        A.a[1][0]=1;A.a[1][1]=1%mod;
        A.a[2][1]=b%mod;A.a[2][2]=1;
        A=Mqpow(A,p-now);
        ans=(A.a[0][0]*ans%mod+(res+b)%mod*A.a[1][0]%mod+A.a[2][0]%mod)%mod;
        res=(res+b*(p-now))%mod;
        now=p;
        //cout<<ans<<endl;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
-- SPDX-License-Identifier: X11
-- 2020-08-23
-- StepMultiple of 9

module Main where

import Data.Char (digitToInt)
import Data.List (foldl')

solve :: [Int] -> String
solve l = if foldl' (\x y -> (x + y) `mod` 9) 0 l == 0
            then "Yes"
            else "No"

parse :: String -> [Int]
parse = map digitToInt

main :: IO ()
main = getLine >>= \x -> putStrLn . solve . parse $ x


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

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}


int main() {
int N,M;
cin>>N>>M;
long long X;
cin>>X;
long long c[15];
long long a[15][15];
for(int i=0; i<N; i++){
    cin>>c[i];
    for(int j=0; j<M;j++){
        cin>>a[i][j];
    }
    
}
long long tsum=10000000000000;

for(int bit=0; bit<(1<<N); bit++){
    long long algo[15]={};
    long long sum=0;
    vector<int> S = IntegerToVector(bit, N);
    for(int i:S){
        sum+=c[i];
        for(int j=0; j<M; j++){
     algo[j]+=a[i][j];
    }
    }
    bool t=true;
    for(int j=0; j<M; j++){
        if(algo[j]<X) t=false;
    }
    if(t) tsum=min(tsum,sum);
}

if(tsum==10000000000000) cout<<-1<<endl;
else cout<<tsum<<endl;
}

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

int main() {
	int a,b,c,d,e,k;
  cin >>a>>b>>c>>d>>e>>k;
  int p = max({a,b,c,d,e});
  int q = min({a,b,c,d,e});
  if(p - q <= k) printf("Yay!\n");
  else printf(":(\n");
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
  int a;
  cin >> a;

  int left = a/100;
  int right =a%100 ;

  if (left == 0){
    if(right >0 && right <= 12)cout << "YYMM" << endl;
    else cout <<"NA" << endl;
  }
  else if(right == 0){
    if(left >0 && left <= 12)cout <<"MMYY" << endl;
    else cout <<"NA" << endl;
  }
  else{
    if(left > 12 && right <= 12 && right > 0)cout << "YYMM" << endl;
    else if(left <= 12 && right > 12 && left > 0)cout << "MMYY" << endl;
    else if(left <= 12 && right <= 12 && left > 0 && right > 0)cout << "AMBIGUOUS" << endl;
    else cout << "NA" << endl;
  }
}



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

int num[105];
int main() {
	int N, mx=0; cin >> N;
	for(int i=0; i<N; ++i){
	    int a;
	    cin >> a;
	    ++num[a];
	    mx=max(mx, a);
	}
	bool flag=true;
	for(int i=1; i<=mx; ++i){
	    if(i*2<=mx-1){
	        if(num[i]>0) flag=false;
	    }
	    else if(i==(mx+1)/2){
	        if(num[i]!=mx%2+1) flag=false;
	    }
	    else if(num[i]<2) flag=false;
	}
	cout << (flag ? "Possible" : "Impossible") << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		int h[]=new int[n];
		for(int i=0;i<n;i++){
			h[i]=sc.nextInt();
		}
		int count=0;
		int max=0;

		for(int i=1;i<n;i++){
			if(h[i]<=h[i-1]){
				count++;
			}else{
				if(max<count){
					max=count;
				}
				count=0;
			}
		}
		if(max<count){
			max=count;
		}
		System.out.println(max);

	}
}


Measured memory_bytes: 50756
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	string A ,B ; cin >> A >> B;
	string S = A + B;
	string res = "No";
	int IS = stoi(S);
	double loo = sqrt(IS);
	
	int lo = (int)loo;

	if (IS == lo * lo) res = "Yes";

	cout << res << endl;

}

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


int MOD=1000000007;

int main(void){
    int A,B,C,ans;
    cin >> A >> B >> C;
    ans=C-(A-B);
    if(ans>0) cout << ans << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
        new Main();
    }
 
    public Main(){
    	new AOJ2149().doIt();
    }
    
    
    class AOJ2149{
    	int n,a,b,c,x;
    	int[] frame;
    	
    	void solve(){
    		int result = -1;
    		int cnt = 0;
    		int nx = x;
    		for(int s=0;s<=10000;s++){
    			if(frame[cnt]==nx){
    				cnt++;
    			}
    			nx = (a*nx+b)%c; 
//    			System.out.println(s+" "+nx);
    			if(cnt==n){
    				result = s;break;
    			}
    		}
    		System.out.println(result);
    	}
    	
    	void doIt(){
    		while(in.hasNext()){
    			n = in.nextInt();
    			a = in.nextInt();
    			b = in.nextInt();
    			c = in.nextInt();
    			x = in.nextInt();
    			if(n+a+b+c+x==0)break;
    			frame = new int[n];
    			for(int i=0;i<n;i++)frame[i] = in.nextInt();
    			solve();
    		}
    	}
    }
    
}

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

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N, M, C;
    N = sc.nextInt();
    M = sc.nextInt();
    C = sc.nextInt();
    
    int B[] = new int[M];
    for (int i=0; i<M; i++) {
      B[i] = sc.nextInt();
    }
    
    int count = 0;
    for (int i=0; i<N; i++) {
      int sum = 0;
      for (int j=0; j<M; j++) {
        sum += B[j]*sc.nextInt();
      }
      if (sum+C > 0)
        count++;
    }

    System.out.println(count);
  }
}


Measured memory_bytes: 24404
import math
a,b = map(int, input().split())
ans = [[] for _ in range(2)]
p1_min = math.ceil(a*100/8)
p1_max = math.ceil((a+1)*100/8)
for i in range(p1_min,p1_max):
    ans[0].append(i)
    
p2_min = math.ceil(b*100/10)
p2_max = math.ceil((b+1)*100/10)
for i in range(p2_min,p2_max):
    ans[1].append(i)

if (ans[0][0] >= ans[1][0]):
    if (ans[1][-1] >= ans[0][0]):
        print(ans[0][0])
    else:
        print(-1)
else:
    if (ans[0][-1] >= ans[1][0]):
        print(ans[1][0])
    else:
        print(-1)

Measured memory_bytes: 3064
def factrize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n ,1))
    return fct

N, P = map(int, input().split(' '))

fct = factrize(P)
fct = sorted(fct, key=lambda x:x[1])

gcf = 1

for i, value in enumerate(fct):
    if N <= value[1]:
        gcf *= value[0] ** (value[1] // N)

print(gcf)

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    if (A <= C && C <= B) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  if(s.size()==26u){
    string t(s);
    if(!next_permutation(t.begin(),t.end())){
      cout<<-1<<endl;
      return 0;
    }
    while(t.substr(0,t.size()-1)>s) t.pop_back();
    cout<<t<<endl;
  }else{
    for(int i=0;i<26;i++){
      int f=0;
      for(char c:s) if(c-'a'==i) f=1;
      if(f) continue;
      cout<<s<<char('a'+i)<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
"use strict"

const Main= (input)=>{
  const Array=input.split(" ").map((ele)=>{return ele-0})
  const A=Array[0],B=Array[1],K=Array[2]
  
  const resultArray=[]
  for(let i=A;i<A+K&&i<=B;i++){
    resultArray.push(i)
  }
  for(let j=B-K+1;j<=B;j+=1){
    if(j>=A+K)resultArray.push(j)
  }
  const result=resultArray.join("\n")
  console.log(result)
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

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

    string s;
    cin >> s;
    cout << (int)count(s.begin(), s.end(), '1') << endl;

    return 0;
}

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

using namespace std;

double value[45];
int size[45];

double get_value(string &pile){
    bool b_can_move = 0, w_can_move = 0;
    double b_max, w_min;
    double last_value = 0;
    for(int i=0;i<pile.length();i++){
        double value;
        if(pile[i]=='B'){
            if(b_can_move){
                b_max = max(b_max,last_value);
            }
            else{
                b_max = last_value;
            }
            b_can_move = 1;
            if(w_can_move){
                value = (b_max + w_min) / 2;
            }
            else{
                value = b_max + 1;
            }
        }
        if(pile[i]=='W'){
            if(w_can_move){
                w_min = min(w_min,last_value);
            }
            else{
                w_min = last_value;
            }
            w_can_move = 1;
            if(b_can_move){
                value = (b_max + w_min) / 2;
            }
            else{
                value = w_min - 1;
            }
        }
        last_value = value;
    }
    return last_value;
}

void enumerate(int st, int ed,map<double,int> &table ,double value_sum = 0, int size_sum = 0){
    if(st==ed){
        if(table.count(value_sum)){
            table[value_sum] = max(table[value_sum], size_sum);
        }
        else{
            table[value_sum] = size_sum;
        }
    }
    else{
        enumerate(st+1, ed, table, value_sum, size_sum);
        enumerate(st+1, ed, table, value_sum + value[st], size_sum + size[st]);
    }
}

int find_zero_value(int st,int ed,map<double,int> &table ,double value_sum = 0, int size_sum = 0){
    if(st==ed){
        if(table.count(-value_sum)){
            return table[-value_sum] + size_sum;
        }
        else return 0;
    }
    else{
        int get1 = find_zero_value(st+1, ed, table, value_sum, size_sum);
        int get2 = find_zero_value(st+1, ed, table, value_sum + value[st], size_sum + size[st]);
        return max(get1, get2);
    }
}

map<double,int> table, table2;

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        string pile;
        cin>>pile;
        size[i] = pile.length();
        value[i] = get_value(pile);
        //printf("%f\n",value[i]);
    }
    if(n<=20){
        enumerate(0,n,table);
        printf("%d\n",table[0]);
    }
    else{
        /*
        enumerate(0,20,table);
        printf("%d\n",find_zero_value(20,n,table));
        */
        enumerate(0,20,table);
        enumerate(20,n,table2);
        int ans = 0;
        for(map<double,int>::iterator it = table.begin(); it!=table.end(); it++){
            double my_value = it->first;
            if(table2.count(-my_value)){
                int my_size = table[my_value] + table2[-my_value];
                ans = max(ans,my_size);
            }
        }
        printf("%d\n",ans);
        
    }

    return 0;
}

Measured memory_bytes: 134272
using System;
using System.Linq;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var res = 0L;
        var mark = new long[n];
        for (int i = 0; i < a.Length; i++)
        {
            if (0 <= i - a[i]) res += mark[i - a[i]];
            if (i + a[i] < n) mark[i + a[i]]++;
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 45484
from collections import Counter
from scipy.misc import comb

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

num = 0
for v in c.values():
  if v > 1:
      num += comb(v, 2,exact=True)
for k in range(N):
  print(int(num - (c[A[k]]-1)))


Measured memory_bytes: 36612
#include<stdio.h>

int main(void){
  int n,i;
  int x[101];
  scanf("%d\n",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&x[i]);
  }
  
  int s,t,p;
  s=0;
  t=0;
  for(i=1;i<=n;i++){
    s=s+x[i];
    t=t+x[i]*x[i];
  }
  p=s/n;
  
  int y,z;
  y=t-2*s*p+n*p*p;
  z=t-2*s*(p+1)+n*(p+1)*(p+1);
  
  if(y>z){
    printf("%d",z);
  }else{
    printf("%d",y);
  }
  
  return 0;
}

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

using namespace std;

int main()
{

    int a, b , mx = 0, st, sum = 0;

    cin >> a >> b;

    if(a > b)
    {
        mx = a;
        st = a;
    }

    else
    {
        mx = b;
        st = b;
    }

    sum += mx;

    if(a == st)
    {
        a--;
    }

    else
       b--;

    if(a > b)
    {
        mx = a;
        st = a;
    }

    else
    {
        mx = b;
        st = b;
    }

    sum += mx;


    cout << sum << endl;




    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000005
#define LL long long
#define end1 "\n"
#define sp " "
using namespace std;
LL int a,b,n,mark[N],sum,k;
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin>>n>>a>>b; 
	if(a==b)
	{
		if(n!=0)
			cout<<1;
		else
			cout<<0;
		return 0;
	}
	if(a>b || n<2)
	{
		cout<<0;
		return 0;
	}
	if(n==2){
		cout<<1;
		return 0;
	}
	int k=n-2;
	sum=b-a;
	cout<<k*sum+1;
	
}	


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>

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

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

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    vll p(N);
    for(ll i=0;i<N;i++)cin>>p[i];
    
    ll ans=0;
    for(ll i=0;i<N;i++){
        if(p[i]==i+1){
            if(i==N-1){
                ans++;
            }else{
                ll tmp=p[i];
                p[i]=p[i+1];
                p[i+1]=tmp;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    int n;
    while (cin>>n, ~n) {
        if (!n) { cout << 0 << endl; continue; }
        int i = 1<<20;
        while (n < i) i >>= 2;
        for (; i>=1; i>>=2) { cout << n / i; n %= i; }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#import itertools
#K = int(input())
N,K = map(int,input().split())
n=[a for a in range(1,N+1)]
c=[]
for i in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    for j in A:
            if j in n and j not in c:
                c.append(j)

#N = str(input())
print(len(n)-len(c))


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

int main()
{
    string s;
    cin>>s;
    int f=0,len;
    len = s.length();
    for(int i=0;i<len;i++){
        if(s[i]=='7')f=1;
    }
    if(f == 1)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
  int n;cin>>n;
  
  vector<int> order={0,1,2};
  
  vector<vector<int>> kou(n,vector<int>(3));
  
  rep(i,n) {
    rep(j,3) cin>>kou[i][j];
  }
  
  vector<vector<int>> dp(n+1,vector<int>(3,0));
  
  
  rep(i,n) {
    rep(j,3) {
      dp[i+1][(j+1)%3]=max(dp[i][j]+kou[i][(j+1)%3],dp[i][(j+2)%3]+kou[i][(j+1)%3]);
    }
  }
  
  cout<<max(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;
  
  
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n,p;
    cin >> n >> p;
    string s;
    cin >> s;
    if(p==2){
    	ll ans=0;
    	for(int i=s.length()-1;i>=0;i--){
    		if((s[i]-'0')%2==0)ans+=i+1;
    	}
    	cout << ans << endl;
    	return 0;
    }
    if(p==5){
    	ll ans=0;
    	for(int i=s.length()-1;i>=0;i--){
    		if((s[i]-'0')%5==0)ans+=i+1;
    	}
    	cout << ans << endl;
    	return 0;
    }
    ll a[n],t=s[n-1]-'0',b=t%p,c=10;a[n-1]=b;
    for(int i=s.length()-2;i>-1;i--){
        t=s[i]-'0';
        b=(c*t+b)%p;
        a[i]=b;
        (c*=10)%=p;
    }
    ll num[p];
    for(int i=0;i<p;i++)num[i]=0;
    num[a[0]]=1;
    ll ans=0;
    for(int i=1;i<n;i++){
        ans+=num[a[i]];
        num[a[i]]+=1;
    }
    ans+=num[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a), greater<>());    
    int cnt = 1;
    vector<ll> heightWidth;
    for (int i=1; i<n; i++) {
        if (a[i]==a[i-1]) cnt++;
        else cnt = 1;

        if (cnt==2) heightWidth.push_back(a[i]);
        if (cnt==4) heightWidth.push_back(a[i]);

        if (heightWidth.size()>=2) break;
    }
    ll ans;
    if (heightWidth.size()>=2) {
        ans = heightWidth[0] * heightWidth[1];
    } else {
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
def main():
    from math import e, pi
    A,B,H,M = map(int,input().split())
    #弧= 半径*ラジアン
    #ラジアン=弧/半径 
    argA = (H + M/60)/12*2*pi #半径1の弧
    argB = M/60*2*pi
    pA = A*pow(e,complex(0,argA))
    pB = B*pow(e,complex(0,argB))
    print(abs(pA - pB))
main()

Measured memory_bytes: 62752
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=2e5+10;
int n,a[maxn];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	int m=unique(a,a+n)-a;
	if(n==m) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 1024
import re

content = input()
pattern = 'R+L+'

results = re.findall(pattern, content)


ans = [0] * len(content) 
pos = 0
for s in results:
    #print(s)

    rcnt = s.count("R")
    lcnt = len(s)-rcnt

    r = l = 0
    x = rcnt//2 + lcnt//2
    r += x
    l += x
    if rcnt%2 == 1: l += 1
    if lcnt%2 == 1: r += 1

    ans[pos + rcnt -1] = l
    ans[pos + rcnt   ] = r
    pos += len(s)


print(*ans)



Measured memory_bytes: 9712
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[2] = {0, 1}, dy[2] = {1, 0};

const int MAX_H = 1000, MAX_W = 1000;
int H, W;
string field[MAX_H];
ll dp[MAX_H][MAX_W];


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

  cin >> H >> W;
  rep(i, H) cin >> field[i];

  dp[0][0] = 1;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (field[i][j] == '#') continue;
      for (int k = 0; k < 2; ++k) {
        int x = i + dx[k], y = j + dy[k];
        if (0 <= x && x < H && 0 <= y && y < W && field[x][y] == '.') {
          dp[x][y] = mod(dp[x][y]+dp[i][j], MOD);
        }
      }
    }
  }

  cout << dp[H-1][W-1] << endl;

  return 0;
}


Measured memory_bytes: 9600