akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 100
#define INF 10000000
#define WHITE 0
#define BRACK 1


int n,color[N],A[N][N],B[N],C[N];

void prim()
{
  int min,i,j;

  for(i=0; i<n; i++){
    B[i] = INF;
    C[i] = -1;
    color[i] = WHITE;
  }

  B[0] = 0;

  while(1){
    min = INF;
    for(i=0; i<n; i++){
      if(color[i] != BRACK && B[i] < min){
	min = B[i];
	j=i;
      }
    }

    if(min == INF) break;
    color[j] = BRACK;

    for(i=0; i<n; i++){
      if(color[i] !=BRACK && A[j][i] < B[i] && A[j][i]>=0){
	C[i] =j;
	B[i] = A[j][i];
      }
    }
  }
}
int main()
{
  int i,j,con=0;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d",&A[i][j]);
    }
  }
  prim();
  for(i=0; i<n; i++)con+=B[i];
  
  printf("%d\n",con);
  return 0;
}



Measured memory_bytes: 2052
read n m
a=(`dd`)
s=0
for b in ${a[@]};do
 s=$[s+b]
done
c=0
for b in ${a[@]};do
 if [ $[b*4*m] -ge $s ];then
  c=$[c+1]
 fi
done
[ $c -lt $m ]&&echo No||echo Yes

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int a,b,c;
	cin>>a>>b>>c;
	a=b*10+c;
	if(a%4==0)
		cout<<"YES";
	else
		cout<<"NO";
	
    return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal
import java.math.RoundingMode
import java.util.*

fun main(args: Array<String>) {
    val (N,K) = readLine()!!.split(" ").map(String::toInt)
    val P = readLine()!!.split(" ").map(String::toDouble)

    var plus = 0.0
    var queue = ArrayDeque<Double>()

    for(i in 0 until K-1){
        var current = 0.5 * (P[i]+1)
        plus += current
        queue.offer(current)
    }

    var max = plus

    for(i in K-1 until N){
        var current = 0.5 * (P[i]+1)

        plus += current
        max = Math.max(plus,max)
        queue.offer(current)
        plus -= queue.poll()
    }

    var big = BigDecimal(max).divide(BigDecimal.ONE,13,RoundingMode.HALF_UP)
    println(big)
}

Measured memory_bytes: 81088
#include<bits/stdc++.h>
using namespace std;
 
 
 
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	long long k;
	cin>>n>>k;
	vector<pair<int,int> > v;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		v.push_back({x,y});
	}
	sort(v.begin(),v.end());
	
	long long cnt = 0;
	int i = 0;
	while(cnt < k && i < n){
		cnt += v[i].second;
		i++;
	}
	i--;
	cout<<v[i].first;
	
	return 0;
}


Measured memory_bytes: 4256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, M;
int A[2200], B[2200], p[1050];

vector<int> Adj[1005];

int depth[1050], used[1050];

void INIT(void) {
	for (int i = 1; i <= N; i++) {
		depth[i] = 0; used[i] = 0; p[i] = -1;
	}
}

int min_depth;
vector<int> ans;

void update(int K, int h) {

	//cout << "K= " << K << "  h= " << h << endl;
	
	int x = K;
	vector<int> tmp;
	while (1) {
		tmp.push_back(x);
		//cout << x << endl;
		if (x == h) {
			min_depth = depth[K] - depth[h]; ans = tmp;  break;
		}
		x = p[x]; if (x <= 0) { break; }
	}
}

void CALL(int K, int d) {

	used[K] = 1;
	depth[K] = d + 1;

	for (auto h : Adj[K]) {
		if (used[h] == 1) {
			if (depth[K] - depth[h] < min_depth) { update(K, h); }
		}
		else {
			p[h] = K; CALL(h, d + 1);
		}
	}
}

int main(void) {

	cin >> N >> M;

	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i];
		Adj[A[i]].push_back(B[i]);
	}

	min_depth = 9999;

	for (int i = 1; i <= N; i++) {
		INIT();
		p[i] = 0;
		CALL(i, 0);
	}

	if (ans.size() == 0) { cout << -1 << endl; }
	else {
		cout << ans.size() << endl;
		for (int i = ans.size() - 1; i >= 0; i--) {
			cout << ans[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;
typedef long long ll;

int main(){

  string s;

  getline(cin, s);

  for(int i=0; i<s.size(); i++){
    if(s[i]>='a' && s[i]<='z'){
      s[i] = s[i]-'a'+'A';
    }else if(s[i]>='A' && s[i]<='Z'){
      s[i] = s[i]-'A'+'a';
    }
  }
  cout<<s<<endl;
}

Measured memory_bytes: 3188
# coding: utf-8
# Here your code !

def func():
    result = ""
    
    index = 0
    while (True):
        try:
            line = input().rstrip()
            num = int(line)
        except:
            print("input error")
            return -1
        
        if (num == 0):
            break

        index += 1
        result += "Case "+str(index)+": "+str(num)+"\n"
    
    print(result.rstrip())

func()

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

typedef int i32;
typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;


template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};


#define debug(x)  cerr<<x<<"\n";
#define loop(i,n) for(i32 i = 0; i < n; ++i)
#define pi  pair<int,int>
#define ti  tuple<int,int,int>
#define mt  make_tuple
#define mk  make_pair
#define vi  vector<int>
#define vll vector<i64>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";
using namespace std;

int main() 
{ 
	i32 n,k;
    cin>>n;
    vector<int> v(n);
    vector<int> temp(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
	temp=v;
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        if (temp[i] < v[n/2]) {
            cout << v[n/2];
        } else {
            cout << v[n/2-1];
        }
        cout <<"\n";
    }
	
    return 0; 
} 



Measured memory_bytes: 3712
x_1 , y_1 , x_2 , y_2 = map(int, input().split())

x_3 , y_3 = x_2 - (y_2 - y_1) , y_2 + (x_2 - x_1)
x_4 , y_4 = x_1 - (y_2 - y_1) , y_1 + (x_2 - x_1)

print(x_3 , y_3, x_4 , y_4 )

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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 main()
{
  INT(N);
  INT(M);
  vector<P> vec(M);
  REP(i,M){
    int a,b;
    cin >> a >> b;
    vec[i].fi=a;
    int cnt = 0;
    REP(j,b){
      int x;
      cin >> x;
      x--;
      cnt+=pow(2,x);
    }
    vec[i].se=cnt;
  }

  vector<vector<ll>> dp(1010,vector<ll>(4200,INF));
  dp[0][0]=0;
  REP(i,M){
    REP(j,1<<N){
      chmin(dp[i+1][j|vec[i].se],dp[i][j]+vec[i].fi);
      chmin(dp[i+1][j],dp[i][j]);
    }
  }

  if(dp[M][(1<<N)-1]<1000000000){
    cout << dp[M][(1<<N)-1] << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 37008
n, m = map(int, input().split())
# x,yは既にソートされている
x = [0] + list(map(int, input().split()))
y = [0] + list(map(int, input().split()))

"""
図で考えるより、数式を眺めた方が見通しが良い

Σ_{1<=i<j<=n} Σ_{1<=k<l<=m} (x_j - x_i) (y_l - y_k)
（↓変数分離のような変形をする）
Σ_{1<=i<j<=n}(x_j - x_i) * Σ_{1<=k<l<=m}(y_l - y_k)

2つのΣは同じ形をしているので、左のΣの求め方を考えれば良い

n=5 で実験してみると、
x5-x4, x5-x3, x5-x2, x5-x1
x4-x3, x4-x2, x4-x1
x3-x2, x3-x1
x2-x1
+x_iは(i-1)個, -x_iは(n-i)個ある
i = 1,2,...,nについて計算すれば、O(n)で計算が可能
"""
tmp1 = 0
tmp2 = 0
for i in range(1, n + 1):
    tmp1 += (i - 1) * x[i] - (n - i) * x[i]
for j in range(1, m + 1):
    tmp2 += (j - 1) * y[j] - (m - j) * y[j]

mod = 10**9 + 7
ans = (tmp1 % mod) * (tmp2 % mod)
ans %= mod
print(ans)


Measured memory_bytes: 98264
#include<stdio.h>
#include<stdlib.h>
int m[101][101],p[101];
int  matrixco(int);

int main(){
  int n;
  int i,j,r,c;
  scanf("%d",&n);

for(i=0;i<n;i++){
  scanf("%d %d",&p[i],&p[i+1]);
 }

matrixco(n);


  return 0;
}
int  matrixco(int n){

  int b,c,d,e;
for(b=0;b<n;b++)scanf("%d%d",&p[b],&p[b+1]);
  for(b=1;b<=n;b++){
    m[b][b]=0;
  }
  for(e=2;e<=n;e++){
    for(b=1;b<=n-e+1;b++){
      c=b+e-1;
      m[b][c]=100000000;
      for(d=b;d<=c-1;d++){
        if(m[b][c]>m[b][d] +m[d+1][c]+p[b-1]*p[d]*p[c]){
          m[b][c]=m[b][d]+m[d+1][c]+p[b-1]*p[d]*p[c];
        }
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0 ;
}




Measured memory_bytes: 2148
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cnt = 0

for i in range(n):
    for j in range(i+1, n):
        s = 0
        for k in range(d):
            s += (x[i][k] - x[j][k])**2
        if math.sqrt(s) % 1 == 0:
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 100000000
#define MOD 100000007
#define SIZE 100005
#define PI 	3.14159265358979323846


int main(){
    ld a,b,c;
    cin >> a >> b >> c;
    ld rad = c*PI/180.00000000;
    ld l = (ld)pow(a,2)+(ld)pow(b,2)-(ld)(2*a*b*(ld)cos(rad));
    l = (ld)sqrt(l);
    printf("%.13llf\n",(ld)(a*b*(ld)sin(rad)/2));
    printf("%.13llf\n",(ld)(a+b+l));
    printf("%.13llf\n",(ld)(b*(ld)sin(rad)));
}


Measured memory_bytes: 3420
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<string>
//int mod(int a,int b,int d);

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

int main() {
  int x;
  cin >> x;
  if(x>=30) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3672
//#pragma comment(linker, "/stack:100000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define debug puts
#define setp cout << fixed << setprecision(15)
#define fst ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int MOD=998244353;
char s[500];
int n;
int run(int l,int r){
    l=1,r=r;
    int cnt=0;
    set<char> a,b;
    for(int i=1;i<=r;i++)
        a.insert(s[i]);
    for(int i=r+1;i<=n;i++)
        b.insert(s[i]);
    for(auto ch:a){
//            cout <<"ch="<<ch<<endl;
        if(b.find(ch)!=b.end()) cnt++;
    }
//    cout << cnt << endl;
    return cnt;
}

int main(void){
    fst;
    cin >> n >> s+1;
    int mx=0;
    for(int i=1;i<=1;i++){
        for(int j=i;j<=n-1;j++){
            mx=max(mx,run(i,j));
        }
    }
    cout << mx << endl;
    return 0;
}
void bef0re_submit(){
    debug("Make sure the algorithm is right!");
    debug("LONG LONG!!!");
    debug("n==0?1?2?3?");
    debug("Make sure output format is right/// Yes??YES  (%.20LF)???");
    debug("if all meet,run with special situation!!!");
    debug("I confirm that I have done all above");

    debug("If u know brute,consider fast,binary(log) or tree?");
}


/*********

*********/


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef ll Weight;
struct Edge {
  int src;
  int dest;
  Weight weight;
  Edge(int src, int dest, Weight weight) : src(src), dest(dest), weight(weight) {;}
  bool operator<(const Edge &rhs) const {
    if (weight != rhs.weight) { return weight > rhs.weight; }
    if (src != rhs.src) { return src < rhs.src; }
    return dest < rhs.dest;
  }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void PrintMatrix(const Matrix &matrix) {
  for (int y = 0; y < (int)matrix.size(); y++) {
    for (int x = 0; x < (int)matrix[y].size(); x++) {
      printf("%lld ", matrix[y][x]);
    }
    puts("");
  }
}


int n;
Graph g;
bool leaf[1000];
int parents[1000];
ll weights[1000];

pair<int, ll> dfs(int from, int parent) {
  pair<int, ll> ret = make_pair(from, 0);
  FORIT(it, g[from]) {
    int to = it->dest;
    if (to == parent) { continue; }
    if (leaf[to]) { continue; }
    pair<int, ll> nret = dfs(to, from);
    nret.second += it->weight;
    if (ret.second < nret.second) { ret = nret; }
  }
  return ret;
}

pair<ll, bool> calc(int from, int parent, int dest) {
  pair<ll, bool> ret = make_pair(0, from == dest);
  FORIT(it, g[from]) {
    int to = it->dest;
    if (to == parent) { continue; }
    if (leaf[to]) { continue; }
    pair<ll, bool> nret = calc(to, from, dest);
    ret.first += nret.first;
    if (nret.second) {
      ret.first += it->weight;
      ret.second = true;
    } else {
      ret.first += it->weight * 2;
    }
  }
  return ret;
}

int main() {
  while (scanf("%d", &n) > 0 && n) {
    ll all = 0;
    MEMSET(leaf, false);
    g = Graph(n);
    REP(i, n - 1) {
      scanf("%d", &parents[i]);
      parents[i]--;
    }
    REP(i, n - 1) {
      scanf("%lld", &weights[i]);
      g[i + 1].push_back(Edge(i + 1, parents[i], weights[i]));
      g[parents[i]].push_back(Edge(parents[i], i + 1, weights[i]));
      all += weights[i];
    }
    REP(i, n) { leaf[i] = g[i].size() == 1; }
    int src = dfs(0, 0).first;
    int dest = dfs(src, src).first;
    ll ans = calc(src, src, dest).first + all;
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 1428
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using ll = long long;
using namespace std;
ll N, A, B;
ll v[100005];
bool check(const ll x) {
  const ll d = A - B;
  ll rest = x;
  ll base = x * B;
  for (int i = 0; i < N; ++i) {
    ll c = v[i];
    if (c <= base) return true;
    ll cct = min(rest, (c - base - 1) / d + 1);
    c -= cct * d;
    rest -= cct;

    if (c > base) return false;
  }

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

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

  sort(v, v + N, greater<ll>());
  ll l = 1;
  ll r = 1E9 + 0.1;

  ll ret;
  while (l <= r) {
    ll mid = l + (r - l) / 2;
    bool rr = check(mid);
    // cout << "mid: " << mid << ' ' << rr << endl;
    if (rr) {
      ret = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }

  cout << ret << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
 
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
typedef long long ll;
typedef unsigned long ul;
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    string S;
    cin >> S;
    
    // calculation
    ll ans = 0, cnt = 0;
    ll len = (ll)S.length();
    REP(i, len) {
        if (S[i] == 'B') {
            cnt++;
        } else {
            ans += cnt;
        }
    }
  
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3428
import java.io.*;
import java.util.*;
import java.awt.Point;
public class Main {
	static Scanner sc;
	static PrintWriter out;
	static ArrayList<Integer> red,green,colorless;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		int n = sc.nextInt(), x = sc.nextInt()-1, y = sc.nextInt()-1;
		int[] edges = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				int edge = Math.min(j-i, Math.min(Math.abs(x-i)+Math.abs(j-y), Math.abs(y-i)+Math.abs(j-x))+1);
				edges[edge]++;
			}
		}
		for (int i = 1; i < n; i++) {
			out.println(edges[i]);
		}
		out.close();
	}
	static class Scanner{
		private BufferedReader br;
		private StringTokenizer st;
		public Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		public String next() throws IOException{
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException{
			return Long.parseLong(next());
		}
		public double nextDouble() throws IOException{
			return Double.parseDouble(next());
		}
		public int[] inArr(int n) throws Exception{
			int a [] = new int[n];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<n;i++) {
				a[i] = Integer.parseInt(st.nextToken());
			}
			return a;
		}
	}

}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T>
T pow_ (T x, T n, T M){
    uint64_t u = 1, xx = x;
    while (n > 0){
        if (n&1) u = u * xx % M;
        xx = xx * xx % M;
        n >>= 1;
    }
    return static_cast<T>(u);
};

template <class T> class Factorial {
    T mod;
    vector<uint64_t> facts, factinv;

public:
    Factorial(int n, T mod) : facts(static_cast<u32>(n+1)), factinv(static_cast<u32>(n+1)), mod(mod) {
        facts[0] = 1;
        for (int i = 1; i < n+1; ++i) facts[i] = facts[i-1]*i % mod;
        factinv[n] = pow_(facts[n], static_cast<uint64_t>(mod - 2), static_cast<uint64_t>(mod));
        for (int i = n-1; i >= 0; --i) factinv[i] = factinv[i+1] * (i+1) % mod;
    }

    T fact(int k) const {
        if(k >= 0) return static_cast<T>(facts[k]);
        else return static_cast<T>(factinv[-k]);
    }

    T operator[](const int &k) const {
        if(k >= 0) return static_cast<T>(facts[k]);
        else return static_cast<T>(factinv[-k]);
    }

    T C(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return static_cast<T>(facts[p]*  factinv[q] % mod * factinv[p-q] % mod);
    }

    T P(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return static_cast<T>((facts[p] * factinv[p-q]) % mod);
    }

    T H(int p, int q) const {
        if(p < 0 || q < 0) return 0;
        return static_cast<T>(q == 0 ? 1 : C(p+q-1, q));
    }
};

int main() {
    int n;
    cin >> n;
    Factorial<ll> f(n, MOD);
    ll ans = f[n-1]*(n-1)%MOD;
    for (int i = 1; i <= n-2; ++i) {
        (ans += (MOD-f.C(i-1, n-i-1))*f[n-i-1]%MOD*f[i]) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 15872
#include<stdio.h>

#define PI 3.141592653589793238462643383279502884197169399375

int main(void)
{
	double r ;
	double x,y ;
	scanf("%lf",&r);
	x=r*r*PI;
	y=2*r*PI;
	printf("%lf %lf\n",x,y);
	return 0 ;
}

Measured memory_bytes: 648
import re
s = input().replace('?', '.')
t = input()
lst = []
for i in range(len(s)-len(t)+1):
  if re.match(s[i:i+len(t)], t):
    lst.append(s[:i].replace('.','a')+t+s[i+len(t):].replace('.','a'))
if lst:
  print(min(lst))
else:
  print('UNRESTORABLE')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 char a[105][105];

int main() {
	int h, w;
	cin >> h >> w;
	vector<string>a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
 
	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}
	
	for (int i = 0; i < h; i++) {
		if (row[i]) {
			for (int j = 0; j < w; j++) {
				if (col[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
}

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

int main(){
    int k;
  	cin >> k;
    vector<ll> a;
    for(int i=1;i<=9;++i) a.push_back(i);
    while(1){
        if(k <= a.size()){
            cout << a[k-1] <<endl;
            return 0;
        }
        k -= a.size();
        vector<ll> old;
        swap(old,a);
        for(ll x :old){
            for(int i=-1;i <= 1;++i){
                int d = x%10 + i;
                if(d <0 || d > 9) continue;
                ll nx = x*10 + d;
                a.push_back(nx);
            }
        }
    }
}

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int& i : a) cin >> i;
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	int alice = 0, bob = 0;
	for (int i = 0; i < N; ++i) {
		if (i % 2) bob += a[i];
		else alice += a[i];
	}
	cout << alice - bob;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222



vll fac, inv, invfac;
void comb_set(ll x = MAX) {
  fac.resize(x + 1, 0);
  invfac.resize(x + 1, 0);
  inv.resize(x + 1, 0);
  fac[0] = inv[1] = invfac[0] = 1;
  FOR(i, 1, x + 1) (fac[i] = fac[i - 1] * i) %= mod;
  FOR(i, 2, x + 1) (inv[i] = (mod - mod / i) * inv[mod%i]) %= mod;
  FOR(i, 1, x + 1) (invfac[i] = invfac[i - 1] * inv[i]) %= mod;
}
ll comb(ll x, ll y) {
  if (x < y) return 0;
  return fac[x] * invfac[x - y] % mod * invfac[y] % mod;
}

ll mod_pow(ll x, ll y) {
  ll ret = 1;
  while (y > 0) {
    if (y & 1) ret = (x*ret) % mod;
    x = (x*x) % mod;
    y >>= 1;
  }
  return ret;
}
ll mod_inverse(ll x) {
  return mod_pow(x, mod - 2);
}

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


  comb_set(MAX);
  ll a, b, c;
  cin >> n >> a >> b >> c;
  ll apow = 1, bpow = 1;
  rep(i, n) {
    (apow *= (a * inv[100 - c]) % mod) %= mod;
    (bpow *= (b * inv[100 - c]) % mod) %= mod;
  }
  ll acur = 1, bcur = 1, cc;
  (cc = c * inv[100]) %= mod;
  (cc = 1 - cc + mod) %= mod;
  cc = mod_inverse(cc);
  rep(i, n) {
    tmp = cc;
    (tmp *= n + i) %= mod;
    (tmp *= comb(n + i - 1, i)) %= mod;
    (ans += (((apow*bcur) % mod)*tmp) % mod) %= mod;
    (ans += (((bpow*acur) % mod)*tmp) % mod) %= mod;
    (acur *= (a * inv[100 - c]) % mod) %= mod;
    (bcur *= (b * inv[100 - c]) % mod) %= mod;
  }
  cout << ans << endl;




  return 0;
}

Measured memory_bytes: 5504
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut scan = Scanner::new(cin);

    let _n = scan.read::<usize>();
    let s = scan.chars();
    let cnt = count(&s);
    println!("{}", if getd(&cnt, 'R') > getd(&cnt, 'B') {"Yes"} else {"No"});
}

#[allow(dead_code)]
fn count<T: Eq + std::hash::Hash + Clone>(slice: &[T]) -> std::collections::HashMap<T, usize> {
    let mut hmap = std::collections::HashMap::new();
    for item in slice {
        *hmap.entry(item.clone()).or_insert(0) += 1;
    }
    hmap
}

// region template
#[allow(dead_code)]
fn getd<S, T>(hmap: &std::collections::HashMap<S, T>, key: S) -> T
    where S : Eq + std::hash::Hash, T : Default + Copy {
    *hmap.get(&key).unwrap_or(&Default::default())
}

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

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

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

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

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

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

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

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

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

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int main(){
  int N;cin>>N;
  REP(i,1,10)REP(j,1,10){
    if(i*j==N){
      print("Yes")
      return 0;
    }
  }
  print("No")
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a = 0, b = 0;
  for(int i = 0; i < 3; i++){
    char c;
    cin >> c;
    if(c == 'A'){
      a++;
    }
    else{
      b++;
    }
  }
  if(a == 3 || b == 3){
    cout << "No";
  }
  else{
    cout << "Yes";
  }
}
      


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int cnt = 0;
    string s;
    cin >> s;
    for (auto i = s.begin(); i != s.end(); ++i) if (*i == 'o') ++cnt;
    if (15 - s.size() + cnt > 7) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iomanip>
#include <iostream>

using namespace std;

int main()
{
	long long n, k;
	long long p[200000];
	long long q[200000];
	
	cin >> n >> k;
	
	q[0] = 0;
	for(long i = 0; i < k; i++) {
		cin >> p[i];
		q[0] += p[i];
	}
	
	for (long i = k; i < n; i++) {
		cin >> p[i];
		q[i - k + 1] = q[i - k] - p[i - k] + p[i];
	}
	
	sort(q, q + n - k + 1);
	
	cout << fixed;
	cout << setprecision(10) << (q[n - k] + k) / 2.0;	
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n) cin >> a[i];
  
  map<int,int> memo;
  rep(i,n) memo[ a[i] ]++;
  
  int ans = 0;
  rep(i,n){
    if(memo[ a[i] ] > a[i]){
      ans += memo[ a[i] ] - a[i];
      memo[ a[i] ] = a[i];
    }
    if(memo[ a[i] ] < a[i]){
      ans += memo[ a[i] ];
      memo[ a[i] ] = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>
#pragma GCC optimize("O2")
#define swap(a,b) ((*a!=*b)&&(*a+=*b,*b=*a-*b,*a-=*b))
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int IMIN=(1<<31);int A[200000],B[200000];long K=0,p=0,m=0,z=0;
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Radix(int A[],const int N)
{
  int temp[200001];
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,N)u[A[i]>>8*k&255]++;
    rep(i,255)u[i+1]+=u[i];
    rep(i,N){temp[--u[A[N-1-i]>>8*k&255]]=A[N-1-i];}k++;
    rep(i,N)v[temp[i]>>8*k&255]++;
    rep(i,255)v[i+1]+=v[i];
    rep(i,N)A[--v[temp[N-1-i]>>8*k&255]]=temp[N-1-i];
  }
}
static inline int check(long x)
{
  long count=0;
  if(x>=0)
  {
    int plus=p-1,minus=m-1;count+=z*(p+m)+z*(z-1)/2+p*m;
    rep(i,plus){while(1l*A[i]*A[plus]>x){plus--;}if(i>=plus){break;}count+=plus-i;}
    rep(i,minus){while(1l*B[i]*B[minus]>x){minus--;}if(i>=minus){break;}count+=minus-i;}
  }
  else{x=-x;int low=0;rep(i,m){while(1l*A[low]*B[m-1-i]<x&&low<p){low++;}count+=p-low;}}
  return count>=K;
}
int main(void)
{
  int N=IN(),x;long l=-2e18,r=-l,mid;K=IN();
  while(N--){x=IN();if(x>0)A[p++]=x;else if(x<0)B[m++]=-x;else z++;}
  Radix(A,p),Radix(B,m);
  while(l<=r){mid=(l+r)/2;if(check(mid))r=mid-1;else l=mid+1;}
  return OUT(l),0;
}

Measured memory_bytes: 2832
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
 
int main(void) {
    string n;
    cin >> n;
    for(int i = 0; i < n.length(); i++){
        if(n[i] == '1'){
            n[i] = '9';
        }else{
            n[i] ='1';
            
        }
    }
    cout << n[0] << n[1] << n[2] << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include<cmath>
#include <ctype.h>
#include <stdlib.h>
#include <vector>
#include <math.h>
#include <stack>
#define ll long long
#define endl '\n'
#define PI 3.14159265
using namespace std;
int frq[26];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("stand.in","r",stdin);
    //freopen("stand.in","w",stdout);
    int k;
    string s;
    cin >> k >> s;
    if (s.size() > k) {
        for (int i = 0; i < k; i++) {
            cout << s[i];
        }
        cout << "...";
    }
    else{
        cout << s;
    }
}
   

Measured memory_bytes: 3652
# -*- coding: utf-8 -*-

memo = ['' for i in xrange(45)]
dp = [0 for i in xrange(45)]


# ?????°?????¨?¨??????????O(2^n)?????????
def recursion(n):
    if n == 0 or n == 1:
        return 1

    return recursion(n - 1) + recursion(n - 2)


# ?????¢??????????????°?¨??????????O(n)?????§????????§??????
def memo_search(n):
    if memo[n] != '':
        return memo[n]
    else:
        if n == 0 or n == 1:
            memo[n] = 1
            return 1
        memo[n] = memo_search(n - 1) + memo_search(n - 2)
        return memo[n]


# ???????¨?????????§????¨??????????O(n)??¨??????
def dynamic_programming(n):
    for i in xrange(n + 1):
        if i == 0 or i == 1:
            dp[i] = 1
        else:
            dp[i] = dp[i - 1] + dp[i - 2]
    return dp[n]


if __name__ == '__main__':
    n = input()
    # print recursion(n)
    # print memo_search(n)
    print dynamic_programming(n)

Measured memory_bytes: 6444
'''
????????£????????????????????????

'''

import queue
v,e,s=map(int,input().split())
edge=[]
inf =1000000100
for i in range(v):
    edge.append([])

for i in range(e):
    vs,vt,d=map(int,input().split())
    edge[vs].append((vt,d))
    
dis=[]
for i in range(v):
    dis.append(inf)

dis[s]=0

q = queue.PriorityQueue()
q.put((0,s))


while(not q.empty()):
    now=q.get()
    nowv=now[1]
    for (vt,d) in edge[nowv]:
        if dis[vt]>dis[nowv]+d:
            dis[vt]=dis[nowv]+d
            q.put((dis[vt],vt))
'''
finished=0
while(finished<v and not q.empty()):
    now=q.get()
    nowv=now[1]
    if now[0]>dis[nowv]: continue
    for (vt,d) in edge[nowv]:
        if dis[vt]>dis[nowv]+d:
            dis[vt]=dis[nowv]+d
            q.put((dis[vt],vt))
    finished+=1       
'''
for i in range(v):
    if dis[i]>=inf:
        print("INF")
    else:
        print(dis[i])

Measured memory_bytes: 90448
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N,M;
  cin>>N>>M;
  vector<ll> vec(N,-1);
  for(ll i=0;i<M;i++) {
ll s,c;
    cin>>s>>c;
    if(vec[s-1]!=-1&&vec[s-1]!=c) {
cout<<-1<<endl;
      return 0;
    }
   
   vec[s-1]=c;
  }
 
  if(N==1&&M==0) {
cout<<0<<endl;
    return 0;
  }
  if(vec[0]==0) {
if(N==1) {
cout<<0<<endl;
  return 0;
}
    else {
cout<<-1<<endl;
    return 0;
    }
  }
  
  for(ll i=0;i<N;i++) {
if(vec[i]==-1) {
if(i==0) {
cout<<1;
}
  else {
cout<<0;
  }
}
    else {
cout<<vec[i];
    }
  }
  
  
  cout<<endl;
}
  
  
  
  
  
 


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

signed main() {
  int N;
  cin >> N;
  
  vector<pair<int, int>> robo(N);
  int X, L;
  for( int i = 0; i < N; i++ ){
    cin >> X >> L;
    robo.at(i) = make_pair( X+L, X-L );
  }
  sort( robo.begin(), robo.end() );
  
  int ans = 0;
  int ichi = -1000000000;
  for( int i = 0; i < N; i++ ){
    if( ichi <= robo.at(i).second ){
      ans++;
      ichi = robo.at(i).first;
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 1792
n = int(input())
l = list(map(int,input().split())) 

totalsqr = (sum(l))**2

individualsqrsum=0
for i in l:
    individualsqrsum += i**2

ans = (totalsqr  - individualsqrsum)  // 2 
ans = ans%(10**9 + 7)
print(ans)

Measured memory_bytes: 31472
N,A,B,C,D = map(int, raw_input().split())
S = raw_input()
i = 1
flagskip = 0
flagskip2 = 0
flagerror = 0
flags = 0
flagstop = 0
flagstop2 = 0
for c in S:
	if(flagstop2 == 1):
		if(c =='#'):
			flagstop += 1
		flagstop2 = 0
	if(i <= A):
		i += 1
		continue
	elif(i == B or (i == D and D < C)):
		if(flags == 1):
			flagstop += 1
		else:
			flagstop2 = 1
	if(c == '#'):
		if(flags == 1):
			flagerror = 1
			break
		flags = 1
		flagskip2 = 0
	else:
		if(flagskip2 == 1):
			flagskip = 1
		elif(flags == 0 and flagskip == 0 and i > B-1 and i < D+1):
			flagskip2 = 1
		flags = 0
	if(i == max(C,D)):
		break
	i += 1
if(flagstop == 2 and flagskip == 0):
	flagerror = 1
if(flagerror == 0):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 2816
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

struct UnionFindTree {
    size_t n;
    vector<int> tree;
    UnionFindTree(size_t n): n(n) {
        tree = vector<int>(n, -1);
    }
    size_t find_root(size_t v) {
        if (tree[v] < 0) return v;
        return tree[v] = find_root(tree[v]);
    }
    bool unite(size_t x, size_t y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return false;
        if (rank(x) < rank(y)) swap(x, y);
        tree[x] += tree[y];
        tree[y] = x;
        return true;
    }
    bool connected(size_t x, size_t y) {
        return find_root(x) == find_root(y);
    }
    int rank(size_t v) {
        return -tree[find_root(v)];
    }
};

int main() {
    size_t N, K, L;
    scanf("%zu %zu %zu", &N, &K, &L);

    UnionFindTree g(N);
    for (size_t i=0; i<K; ++i) {
        size_t p, q;
        scanf("%zu %zu", &p, &q);
        --p, --q;

        g.unite(p, q);
    }

    UnionFindTree h(N);
    for (size_t i=0; i<L; ++i) {
        size_t r, s;
        scanf("%zu %zu", &r, &s);
        --r, --s;

        h.unite(r, s);
    }

    vector<size_t> ar(N), br(N);
    for (size_t i=0; i<N; ++i) {
        ar[i] = g.find_root(i);
        br[i] = h.find_root(i);
    }

    map<pair<size_t, size_t>, int> dict;
    for (size_t i=0; i<N; ++i)
        ++dict[make_pair(ar[i], br[i])];

    for (size_t i=0; i<N; ++i)
        printf("%d%c", dict[make_pair(ar[i], br[i])], i<N-1? ' ':'\n');

    return 0;
}



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

// APG4b-F
int main() {
  string s;
  cin >> s;
  int sum = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '1') {
      sum++;
    }
    
  }

  cout <<  sum << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
// in-short-use macros
 
#define all(c) (c).begin(),(c).end()
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010
 
//main function here
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	if(s[s.size()-1]=='s')
		cout<<s<<"es";
	else
		cout<<s<<"s";
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int gcd(int a,int b)
{
    if(a % b == 0){
        return b;
    }else{
        return gcd(b,a%b);
    }
}

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

int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b) > 0){
        cout << gcd(a,b) << " " << lcm(a,b) << endl;
    }
    return 0;
}

Measured memory_bytes: 3024
# include <iostream>
# include <vector>
# include <string>
# include <stack>


using namespace std;

int main()
{
    int n, a[110], mn = 102, mx = -105;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        mn = min(mn, a[i]);
        mx = max(mx, a[i]);
    }
    
    int ans = 1e9;
    
    for(int i = mn; i <= mx; i++) {
        int s = 0;
        for(int j = 0; j < n; j++) {
            s += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, s);
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

long long trade(long long n, int g_A, int s_A, int b_A, int g_B, int s_B, int b_B)
{
    long long n_Max = n;

    for (int g = 0; g * g_A <= n; g++) {
        if ((g_B - g_A <= 0) && (g > 0)) {break;}

        for (int s = 0; g * g_A + s * s_A <= n; s++) {
            if ((s_B - s_A <= 0) && (s > 0)) {break;}

            int b = 0;
            if (b_B - b_A > 0) {
                b = (n - g * g_A - s * s_A) / b_A;
            } else {
                s = (n - g * g_A) / s_A;
            }

            long long n_New = n + (long long) g * (g_B - g_A) 
                                + (long long) s * (s_B - s_A)
                                + (long long) b * (b_B - b_A);

            if (n_New > n_Max) {
                n_Max = n_New;
            }
        }
    }

    return n_Max;
}

int main(int argc, char *argv[])
{
    long long n;
    int g_A, g_B;
    int s_A, s_B;
    int b_A, b_B;
    int ans;

    std::cin >> n;
    std::cin >> g_A >> s_A >> b_A;
    std::cin >> g_B >> s_B >> b_B;

    // 取引所 A -> B
    n = trade(n, g_A, s_A, b_A, g_B, s_B, b_B);;

    // 取引所 B -> A
    n = trade(n, g_B, s_B, b_B, g_A, s_A, b_A);

    std::cout << n << std::endl;

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b(n);
    copy(a.begin(), a.end(), b.begin());

    int maxv = *max_element(b.begin(), b.end());
    size_t maxi = distance(b.begin(), max_element(b.begin(), b.end()));
    b.erase(b.begin() + maxi);
    int maxv2 = *max_element(b.begin(), b.end());

    rep(i, n) {
        if (a[i] == maxv) cout << maxv2 << endl;
        else cout << maxv << endl;
    }

    return 0;
}


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

#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'

#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

#ifndef __LOCAL
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout); FAST;
#else
#define FILES(namein, nameout) FAST;
#endif //__LOCAL

using namespace std;
using namespace __gnu_pbds;
using python = void;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned short uss;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type> ordered_set;

const ll M = 1e9+7;
const ll N = 1e5+228;
constexpr ll inf = 0x3f3f3f3f3f3f3f3f;
ll w[108], v[108];
ll dp[N];
python solve(){
	FAST;
	ll n, sw;
	cin >> n >> sw;
	for(ll i = 0;i<n;i++){
		cin >> w[i] >> v[i];
		//for(ll se = sw;se>=w[i];--se) dp[se] = max(dp[se], dp[se-w[i]]+v[i]);
	}
	for(ll i = 0;i<N;i++) dp[i] = inf;
	dp[0] = 0;
	for(ll i = 0;i<n;i++){
		for(ll vrt = N-1;vrt>=v[i];--vrt) dp[vrt] = min(dp[vrt], dp[vrt-v[i]]+w[i]);
	}
	ll e  =0;
	for(ll i = N-1;i>=0;i--){
		if(dp[i] <= sw){
			e = i;
			break;
		}
	}
	cout << e << '\n';
}

signed main(){
	FAST;
	ll q = 1;
	//cin >> q;
	while(q--){
		solve();
	}
}

Measured memory_bytes: 1024
def solve(n, m, p):
    tot = 0
    a = 0
    for i in range(n):
        x = int(input())
        tot += 100 * x
        if i == m-1: a = x

    if a == 0:
        print(0)
        return

    tot = tot * (100-p) / 100.0
    ans = int(tot / a)
    print(ans)


while 1:
    n, m, p = map(int, input().split())
    if n == 0: break
    solve(n, m, p)

Measured memory_bytes: 7620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //1000000007


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

    // solution comes here

    double T, A, H, e=1e15;
    ll ans, N;
    cin >> N >> T >> A;
    rep(i, N) {
        cin >> H;
        if(abs(A - (T-H*0.006)) < e) {
            ans=i+1;
            e = abs(A - (T-H*0.006));
        }
    }

    cout << ans << nl;
}

Measured memory_bytes: 256
#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>;

char s_[200100];
int s[200100];
vector<int> rm(2019);
int main() {
	scanf("%s", s_);
	int slen = 0;
	rep(i, 200100) if (s_[slen] != '\0') slen++;
	rep(i, slen) s[i] = s_[i] - '0';
	ll ans = 0;
	rep(i, slen) {
		vector<int> nxtrm(2019);
		int p = s[i];
		nxtrm[p]++;
		rep(j, 2019) {
			nxtrm[(j * 10 + p)%2019] += rm[j];
		}
		swap(nxtrm, rm);
		ans += rm[0];
	}
	cout << ans << endl;
	return 0;
}
/*
	int slen = s.length();
	int ans = 0;
	for(int i = 0; i <= slength() - 4; i++) {
		for(int j = i + 4; j < slength(); j++) {
			int m = 1;
			for(int k = j - 1; k >= i; k--) {

	
	for(int a = 2019; a <= 200000; a += 2019) {
		int d = 0; // len of a
		for(int t = a; t > 0; t /= 10) {
			d++;
		}
		for(int i = 0; i <= (int)s.length() - d; i++) {
			int k = 1;
			int t = 0;
			for(int j = i + d - 1; j >= i; j--) {
				t += (s[j] - '0') * k;
				k *= 10;
			}
			if (a == t) {
				ans++;
			}
			cout << a << '\t' << t << endl;
		}
	}
	cout << ans << endl;
}
*/


Measured memory_bytes: 4644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    vector<vector<int>> a(3,vector<int>(3));

    rep(i,3){
        cin >> a[i][0] >>a[i][1] >> a[i][2];
    }
    int n;
    cin >> n;
    //選ばれた数がビンゴカードにあったらそこを0にする
    rep(i,n){
        int b;
        cin >> b;
        rep(j,3){
            rep(k,3){
                if(a[j][k] == b){
                    a[j][k] = 0;
                }
            }
        }
    }

    //横に揃っているか
    rep(i,3){
        if(a[i][0] == a[i][1] && a[i][1]==a[i][2]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    //縦に揃っているk
    rep(i,3){
        if(a[0][i] == a[1][i] && a[1][i]==a[2][i]){
            cout << "Yes" << endl;
            return 0;
        }
    }

    //斜めに揃っているか
    if(a[0][0] == a[1][1] && a[1][1]==a[2][2]){
        cout << "Yes" << endl;
        return 0;
    }
    if(a[0][2] == a[1][1] && a[1][1]==a[2][0]){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

}

Measured memory_bytes: 3636
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    a, b, c, d = map(int,input().split())
    m = a * c
    if a * d > m:
        m = a * d
    if b * c > m:
        m = b * c
    if b * d > m:
        m = b * d
    print(m)
    

    
if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

int digits(ll val) {
	int digs = 0;
	while(val>0) {
		digs++;
		val/=10;
	}
	return digs;
}

void solve(int test_case) {
	ll n;
	cin>>n;
	for(ll i=sqrt(n)+1;i>=1;i--) {
		if(n%i==0) {
			cout<<max(digits(i),digits(n/i));
			break;
		}
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=100000;
int main(){
      int n,m,h,k;
      while(cin>>n>>m>>h>>k&&(n||m||h||k)){
            vector<int> V[h];
            int p[n],a,b;
            REP(i,n)cin>>p[i];
            int ans=0,d[n],c[n];
            REP(i,m){
                  cin>>a>>b;a--;b--;
                  V[b].PB(a);
            }
            REP(i,n)d[i]=c[i]=i;
            REP(i,h)REP(j,V[i].size())swap(d[V[i][j]],d[V[i][j]+1]);
            REP(i,n)if(d[i]<k)ans+=p[i];
            for(int i=h-1;i>=0;i--){
                  REP(j,V[i].size()){
                        swap(d[V[i][j]],d[V[i][j]+1]);
                        int res=0;
                        REP(l,n)if(d[l]<k)res+=p[c[l]];
                        ans=min(ans,res);
                        swap(d[V[i][j]],d[V[i][j]+1]);
                  }
                  REP(j,V[i].size())swap(d[V[i][j]],d[V[i][j]+1]);
                  REP(j,V[i].size())swap(c[V[i][j]],c[V[i][j]+1]);
            }
            cout<<ans<<endl;
      }
}

Measured memory_bytes: 1812