akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

class BIT{
public:
  ll n,bit[555555];
  BIT(){fill(bit,bit+555555,0);}
  void add(ll i,ll x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  ll sum(ll i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
};

BIT b[26];
void Main() {
  ll n,T;
  string s;
  cin >> n >> s >> T;
  rep(i,26) {
    b[i]=BIT();
    b[i].n=n+1;
    rep(j,n) {
      if(s[j]-'a'==i) b[i].add(j+1,1);
    }
  }
  while(T--) {
    int z;
    R z;
    if(z==1) {
      int x;
      char c;
      cin >> x >> c;
      x--;
      b[s[x]-'a'].add(x+1,-1);
      s[x]=c;
      b[s[x]-'a'].add(x+1,1);
    } else {
      int l,r;
      cin >> l >> r;
      int ans=0;
      rep(i,26) {
        if(b[i].sum(r)-b[i].sum(l-1)) ans++;
      }
      pr(ans);
    }
  }
}

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


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

int main() {
	int a, b, c, t, i=0;
	cin >> a >> b>> c;
	for (int x = a; x <= b; x++){
		t = c % x;
		if (t == 0) i++;
		
	}
	cout << i << endl;
	
	return 0;
}

Measured memory_bytes: 3084
#include "bits/stdc++.h"
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1e9+7
#define inf 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=n;i>=0;i++)
#define all(vec) vec.begin(),vec.end()
#define cend cout<<endl;
#define P pair<int,int>
#define prique priority_queue<P,vector<P>,greater<P>>
using namespace std;

int k;
int cnt=49;

signed main() {
	cin>>k;
	cnt+=k/50;
	k=k%50;
	cout<<50<<endl;
	rep(i,k){
		cout<<cnt+51-k<<" ";
	}
	rep(i,50-k){
		if(i==50-k-1)cout<<cnt-k<<endl;
		else cout<<cnt-k<<" ";
	}
}

Measured memory_bytes: 256
/* it was worth becoming a chemist */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 2e6 + 5;

ll n, a, b;


int main() {	
    #ifndef ONLINE_JUDGE
	//~ freopen(NAME".in", "r", stdin);
    // freopen(NAME".out", "w", stdout);
    #endif
	
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << setprecision(9) << fixed;
    
    cin >> n >> a >> b;
    cout << max((ll)0, ((n - 1) * b + a) - ((n - 1) * a + b) + 1);
    return 0;
}


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

int main(){
  int K,N;
  cin >> K >> N;
  vector<long long> A(2*N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    A.at(i+N)=A.at(i)+K;
  }
  long long mincost=1e9;
  for(int i=0;i<N;i++){
    long long cost=A.at(i+N-1)-A.at(i);
    mincost=min(mincost,cost);
  }
  cout << mincost << endl;
}

Measured memory_bytes: 6384
#include <stdio.h>

int main(void) {
	int now,sum;
	int kosuu,rawkosuu;
	int i;
	while(1) {
		scanf("%d",&rawkosuu);
		if(rawkosuu==0)break;
		kosuu=rawkosuu*(rawkosuu-1)/2;
		for(i=0,sum=0;i<kosuu;i++) {
			scanf("%d",&now);
			sum+=now;
		}
		printf("%d\n",sum/(rawkosuu-1));
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int X,A;
    cin >> X >> A;
    if(X<A)cout << 0 << endl;
    else cout << 10 << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

#t=1
t=ii()
lol=[] 
ans=0
for _ in range(t):
    a,b=ml()    
    lol.append([b,a])
lol.sort()
f=0
for i in range(t):
    if(lol[i][1]+ans<=lol[i][0]):
        ans+=lol[i][1]
    else:
        f=1
        break
if f:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 96552
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, K = sc.nextInt()
    
    val _Sushis = new Array[(Int, Long)](N)
    (0 until N) foreach { i =>
      val t = sc.nextInt()
      val d = sc.nextLong()
      _Sushis(i) = (t, d)
    }
    val Sushis = _Sushis.sortBy(_._2)(Ordering.Long.reverse)

    // f(a)とそれを構成するS_aがわかっている時に
    // f(a+1)とそれを構成するS_a+1をを求めることを考えます(x <= a <= N-1)
    // S_a+1はS_aに以下の操作を加えることで構成することができます
    // 1. 集合S_aから、取り除いても「ネタ」の種類数が減らない寿司の中で最も「おいしさ」の小さいものを取り除く
    //    この時点でネタの種類数が減らないものがない場合には, それまでのものから選ぶ
    // 2. 集合S_aに含まれない寿司の中で、集合S_aにない「ネタ」を持つ、最も「おいしさ」の大きいものをS_aに加える
    // この操作を繰り返すことにより、f(i) (x < i <= N)を再帰的に求めることができます。

    val (initialSushis, restSushis) = Sushis.splitAt(K)
    val sushiset = Set(initialSushis.map(_._1): _*)
    var p = sushiset.size.toLong
    val initialV = initialSushis.foldLeft(0L)(_ + _._2) + p * p

    val removableSushis = scala.collection.mutable.PriorityQueue[(Int, Long)]()(Ordering.by[(Int, Long), Long](_._2).reverse)
    val appendableSushis = scala.collection.mutable.PriorityQueue[(Int, Long)]()(Ordering.by[(Int, Long), Long](_._2))

    {
      val spSushis = initialSushis.sorted(Ordering.Tuple2(Ordering.Int, Ordering.Long.reverse))
      val N = initialSushis.length
      var bef = -1
      var i = 0
      while (i < N) {
        val sushi = spSushis(i)
        if (sushi._1 == bef) {
          removableSushis.enqueue(sushi)
        }
        bef = sushi._1
        i += 1
      }
    }

    {
      val spSushis = restSushis.sorted(Ordering.Tuple2(Ordering.Int, Ordering.Long.reverse))
      val N = spSushis.length
      var bef = -1
      var i = 0
      while (i < N) {
        val sushi = spSushis(i)
        if (!sushiset.contains(sushi._1)) {
          if (sushi._1 != bef) {
            appendableSushis.enqueue(sushi)
          }
          bef = sushi._1
        }
        i += 1
      }
    }

    def solve(bef: Long, max: Long, p: Long): Long =
      if (p < K && removableSushis.nonEmpty && appendableSushis.nonEmpty) {
        val rs = removableSushis.dequeue()
        val as = appendableSushis.dequeue()
        val current = bef - rs._2 + as._2 + 2 * p + 1
        solve(current, max max current, p + 1)
      } else max

    println(solve(initialV, initialV, p))
  }

}


Measured memory_bytes: 120080
#include <iostream>
#include <string>
using namespace std;
 
bool flag;
 
bool check(string t, string u){
 if(u==t){
  if(!flag)cout << "Opened by " << t << endl;
  else cout << "Closed by " << t << endl;
  flag ^= 1;
  return true;
 }
 return false;
}
 
 
int main(){
 int n,i,j,m;
 bool ans=false;
 string u[260],t[260];
 cin >> n;
 for(i=0;i<n;i++)cin >> u[i];
 cin >> m;
 for(i=0;i<m;i++)cin >> t[i];
 for(i=0;i<m;i++){
  ans = false;
  for(j=0;j<n;j++)ans|=check(t[i],u[j]);
  if(!ans)cout << "Unknown " << t[i] << endl;
 }
 return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define MOD 1000000007
using namespace std;

long long int n, dp[100010][2];
std::vector<int> edges[100010];

long long int recursive(int konum, int last, int gel){
	long long int cvp=1, test=0;
	if(dp[konum][last])return dp[konum][last];
	if((edges[konum].size()==1&&edges[konum][0]==gel)||edges[konum].size()==0)
		return 2-last;
	test=1;
	for(int i=0;i<edges[konum].size();i++){
		if(edges[konum][i]==gel)continue;
		test=(test*recursive(edges[konum][i], 0, konum))%MOD;
	}
	cvp=test;
	test=1;
	if(last==0){
		for(int i=0;i<edges[konum].size();i++){
			if(edges[konum][i]==gel)continue;
			test=(test*recursive(edges[konum][i], 1, konum))%MOD;
		}
		cvp=(cvp+test)%MOD;
	}
	dp[konum][last]=cvp;
	return cvp;
}

int x, y;

int main(void){
	cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>x>>y;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	cout<<recursive(1, 0, 0)%MOD;
	return 0;
}

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

#define NM 1002
#define ll long long
#define MM 102

using namespace std;

ll n, X[NM], Y[NM];

int m = 39;

ll d[MM];

ll x[MM], y[MM];

int main()
{
    cin >> n;
    bool ok = true;
    for(int i = 1; i <= n; i++)
    {
        cin >> X[i] >> Y[i];
        if(abs(X[i] + Y[i]) % 2 != abs(X[1] + Y[1]) % 2)
            ok = false;
    }
    if(!ok)
    {
        cout << "-1\n";
        return 0;
    }
    d[1] = 1;
    for(int i = 2; i <= m; i++)
        d[i] = d[i - 1] * 2;
    bool fix = false;
    if(abs(X[1] + Y[1]) % 2 == 0)
    {
        m++;
        d[m] = 1;
        fix = true;
    }
    cout << m << "\n";
    for(int i = 1; i <= m; i++)
        cout << d[i] << " ";
    cout << "\n";
    for(int i = 1; i <= n; i++)
    {
        x[m] = X[i];
        y[m] = Y[i];
        string ans = "";
        ll p2 = 1;
        for(int j = 1; j <= m - 1; j++)
            p2 *= 2;
        for(int j = m - 1; j >= 0; j--)
        {
            x[j] = x[j + 1];
            y[j] = y[j + 1];
            if(abs(x[j] - d[j + 1]) + abs(y[j]) <= p2 - 1 + fix)
            {
                ans += "R";
                x[j] -= d[j + 1];
            }
            else if(abs(x[j] + d[j + 1]) + abs(y[j]) <= p2 - 1 + fix)
            {
                ans += "L";
                x[j] += d[j + 1];
            }
            else if(abs(y[j] - d[j + 1]) + abs(x[j]) <= p2 - 1 + fix)
            {
                ans += "U";
                y[j] -= d[j + 1];
            }
            else if(abs(y[j] + d[j + 1]) + abs(x[j]) <= p2 - 1 + fix)
            {
                ans += "D";
                y[j] += d[j + 1];
            }
            p2 /= 2;
        }
        reverse(ans.begin(), ans.end());
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    for(;;){
        int a,d,n;
        cin >> a >> d >> n;
        if(a == 0 && d == 0 && n == 0){ return 0; }
        int ans = -1;
        for(int i = 0 ; ((a + d * i <= 1000000) && (ans == -1)) ; i++ ){
            bool prime = true;
            if(a + d * i == 1) { prime = false; }
            else{
                for(int j = 2 ; j*j <= a + d * i ; j++){
                    if((a + d * i) % j == 0){ prime = false; }
                }
            }
            if(prime){
                if(n == 1){ ans = a + d * i; }else{ n--; }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3120
N = int(input())
S = list(input())
if len(S) % 2 != 0:
  print('No')
  exit()
for i in range(len(S)//2):
  if S[i] == S[len(S)//2+i]:
    continue
  else:
    print('No')
    exit()
print('Yes')

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

using namespace std;

int A[110000];

int main() {
  int N;
  cin >> N;
  for(int i = 0; i < N; i++) cin >> A[i];
  sort(A, A + N, greater<int>());
  
  int i = 0, j = 0;
  long long e[2] = { };
  while(i < N && j < 2) {
    if(A[i] == A[i + 1]) {
      e[j] = A[i];
      i += 2;
      j++;
    } else {
      i++;
    }
  }
  cout << e[0] * e[1] << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    int n;
    cin >> n;
    vector<int> r(n);
    vector<int> minj(n+1);
    minj[0] = 1000000001;
    for(int i = 0 ; i < n ; i++){
        cin >> r[i];
        minj[i+1] = min(minj[i], r[i]);
    }
    int ans = -1000000001;
    for(int i = 1 ; i < n ; i++){
        int profit = r[i] - minj[i];
        ans = max(ans, profit);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4396
main = do
  [n,x] <- map read . words <$> getLine
  ls <- map read . words <$> getLine
  print $ length $ filter (<=x) $ 0 : b 0 ls 

b :: Int -> [Int] -> [Int] 
b _ [] = []
b n [x] = [n + x]
b n (x:xs) = let d = n + x in d : b d xs

Measured memory_bytes: 892
N, M = [int(_) for _ in input().split()]
xyz = []
for _ in range(N):
    xyz.append([int(_) for _ in input().split()])

ans = -1
for i in range(8):
    sx = -(i >> 2 & 1) or 1
    sy = -(i >> 1 & 1) or 1
    sz = -(i >> 0 & 1) or 1
    xyz.sort(key=lambda v: sx * v[0] + sy * v[1] + sz * v[2], reverse=True)
    x, y, z = 0, 0, 0
    for a in xyz[:M]:
        x += a[0]
        y += a[1]
        z += a[2]
    ans = max(ans, abs(x) + abs(y) + abs(z))
print(ans)


Measured memory_bytes: 40560
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first!=b.first){
        return a.first>b.first;
    }else{
        return a.second>b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    string S=in<string>();
    string ans;
    if(S=="ARC"){
        ans="ABC";
    }else{
        ans="ARC";
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 10000000000000007LL
#define ll long long
using namespace std;
ll cnt[3][50],dif[50][50];
signed main(){
	int n,c;
	cin>>n>>c;
	for(int i=1;i<=c;i++){
		for(int j=1;j<=c;j++){
			cin>>dif[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			int x;
			cin>>x;
			cnt[(i+j)%3][x]++;
		}
	}
	int ans = inf;
	for(int i=1;i<=c;i++){ 
		for(int j=1;j<=c;j++){
			for(int k=1;k<=c;k++){
				if( i!=j && j!=k && i!=k){
					int tmp = 0;
					for(int p=1;p<=c;p++){
						tmp += cnt[0][p] * dif[p][i];
					}
					for(int p=1;p<=c;p++){
						tmp += cnt[1][p] * dif[p][j];
					}
					for(int p=1;p<=c;p++){
						tmp += cnt[2][p] * dif[p][k];
					}
					if(tmp<ans)ans=tmp;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
#define MAX 64

class Piece{
    public: 
    int W, H;
    char G[MAX][MAX];

    void rotate(){
	char t[MAX][MAX];
	rep(i, H) rep(j, W) t[j][H-i-1] = G[i][j];
	swap(W, H);
	rep(i, H) rep(j, W) G[i][j] = t[i][j];
    }

    void trim(){
	int si, sj, ei, ej;
	si = sj = 100;
	ej = ei = -1;
	rep(i, H) rep(j, W) {
	    if ( G[i][j] == '.' ) continue;
	    si = min(i, si);
	    sj = min(j, sj);
	    ei = max(i, ei);
	    ej = max(j, ej);
	}

	char t[MAX][MAX];
	for ( int i = si; i <= ei; i++ ){
	    for ( int j = sj; j <= ej; j++ ){
		t[i-si][j-sj] = G[i][j];
	    }
	}
	W = ej-sj+1;
	H = ei-si+1;
	rep(i, H) rep(j, W) G[i][j] = t[i][j];
    }
};

char G[MAX][MAX], T[MAX][MAX];
int W, H;
Piece p;

bool check( int si, int sj, Piece u ){
    rep(i, H) rep(j, W) T[i][j] = G[i][j];
    rep(i, u.H) rep(j, u.W) {
	if ( G[i+si][j+sj] == '#' && u.G[i][j] == '#' ) return false;
	if ( G[i+si][j+sj] == '#' || u.G[i][j] == '#' ) {
	    T[i+si][j+sj] = '#';
	}
    }
    return true;
}

int getScore(){
    int score = 0;
    for ( int i = 0; i < H; i++ ){
	int cnt = 0;
	for ( int j = 0; j < W; j++ ){
	    if ( T[i][j] == '#' ) cnt++;
	    else break;
	}
	if ( cnt == W ) score++;
    }
    return score;
}

int compute(){
    int maxs = -1;
    for ( int r = 0; r < 4; r++ ){
	for ( int i = 0; i <= H - p.H; i++ ){
	    for ( int j = 0; j <= W - p.W; j++ ){
		if ( check(i, j, p) ){
		    maxs = max( maxs, getScore() );
		}
	    }
	}
	p.rotate();
    }
    return maxs;
}

int main(){
    int tcase;  cin >> tcase;
    for ( int t = 0; t < tcase; t++ ){
	cin >> p.H >> p.W;
	rep(i, p.H) rep(j, p.W) cin >> p.G[i][j];
	cin >> H >> W;
	rep(i, H) rep(j, W) cin >> G[i][j];
	p.trim();
	cout << compute() << endl;
    }
    return 0;
}

Measured memory_bytes: 1180
using System;

class Sample33
{
    public static void Main()
    {
        string word = Console.ReadLine().Trim();
        int count = 0;
        int sNumber ;
        
        while (true)
        {
            string[] sentences = Console.ReadLine().Trim().Split(' ');
            
            //終了処理
            if (sentences[0] == "END_OF_TEXT")
            {
                break;
            }
            
            sNumber = sentences.Length ;
            
            for (int i = 0 ; i < sNumber ; i++)
            {
                if (word.ToUpper() == sentences[i].ToUpper())
                {
                    count++;
                }
            }
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 15884
import java.util.*;
public class Main {

	public static void main(String[] args) {
		int a=0,b=0,ans=0;
		Scanner sc = new Scanner(System.in);
		String c = sc.next();
		a = c.indexOf('A');
		for(int i = a+1;i < c.length();i++) {
			if(c.charAt(i) == 'Z')b = i;
		}
		ans = b - a + 1;
		System.out.println(ans);
	}

}


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

using namespace std;

#define MAXN int(1e5 + 10)

// asdhfadsgfkjasdf
//fasdfjasjdfgkjaf
//dsfkasjdfjagsdjkfas
//adsfkjasldfjasf

int n, arr[MAXN];
int mar[MAXN];

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) cin >> arr[i];
	sort(arr, arr + n, greater<int>());
	for (int i = 0; i < n; i++)
		mar[arr[i]]++;
	int D = arr[0];
	for (int i = 0; i <= D; i++) {
		int me = max(D - i, i);
		if (!mar[me])
			return cout << "Impossible\n", 0;
		mar[me]--;
	}
	for (int i = 0; i <= ((D - 1)/ 2) + 1; i++)
		if (mar[i])
			return cout << "Impossible\n", 0;
	cout << "Possible\n";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
data = list(map(int, input().split()))
wa = list()
b4 = 0
mins = 99999999
for i in range(n):
    if i == 0:
        wa.append(data[i])
    else:
        wa.append(data[i]+wa[i-1])

for i in range(n):
    if mins > abs(wa[-1]-wa[i] - wa[i]):
        mins = abs(wa[-1]-wa[i] - wa[i])
print(mins)

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define zeroes(x) memset(x,0,sizeof(x))
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;

int main()
{		
	
   
    IOS
    int n,m;
    cin>>n>>m;
    ll dp[n+1][m+1],a[n+1][m+1];
    memset(a,0,sizeof(a));
    for(ll i=0;i<n;i++)
    {
        string s;
        cin>>s;
        for(ll j=0;j<m;j++)
            {
                if(s[j]=='#')
                    a[i+1][j+1]=1;   
            }
    }


    memset(dp,0,sizeof(dp));
    
    dp[1][1]=1;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(!a[i-1][j]) dp[i][j]+=dp[i-1][j];
            if(!a[i][j-1]) dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
        }
    }


    cout<<dp[n][m];





}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,D=MAP()

print(ceil(N, (D*2+1)))


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

using namespace std;
#define ll long long
const long long mod=1e9+7;
const int maxn=2e6+7;

ll fac[maxn*2+1],inv_fac[maxn*2+1];

ll quickpow(ll x,ll n){
    ll res=1;
    x=x%mod;
    while(n){
        if(n&1)res=(res*x)%mod;
        n>>=1;
        x=(x*x)%mod;
    }
    return res;
}


void init(){
    fac[0]=1;
    for(int i=1;i<=maxn;i++) fac[i]=(fac[i-1]*i)%mod;
    inv_fac[maxn]=quickpow(fac[maxn],mod-2);
    for(int i=maxn-1;i>=0;i--) inv_fac[i]=(inv_fac[i+1]*(i+1))%mod;
}

ll C(int n,int m){
    if(n < 0 || m < 0 || m > n) return 0;
    if(m == 0 || m == n) return 1;
    return fac[n]*inv_fac[n-m]%mod*inv_fac[m]%mod;
}
int main (){
	init();
	int k;cin>>k;
	string ss;cin>>ss;
	int n=ss.size();
	ll ret = quickpow(26,n+k);
	for(int i=0;i<n;i++){
		ll tmp=C(n+k,i)*quickpow(25,n+k-i);
		tmp%=mod;
		ret-=tmp;ret+=mod;ret%=mod;
	}
	cout<<ret%mod<<endl;
	return 0;
}




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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (auto& e : s) cin >> e;

  int r = 1e9;
  for (int b = 0; b < (1 << h - 1); b++) {
    int rb = bitset<9>(b).count();
    vector<int> m(h);
    for (int i = 1; i < h; i++) m[i] = m[i - 1] + ((b >> i - 1) & 1);

    bool valid = true;
    vector<int> c(h);
    for (int j = 0; j < w && valid; j++) {
      bool should_cut = false;
      for (int i = 0; i < h; i++) {
        c[m[i]] += s[i][j] == '1';
        should_cut = should_cut || c[m[i]] > k;
      }
      if (should_cut) {
        rb++;
        for (auto& e : c) e = 0;
        for (int i = 0; i < h; i++) {
          c[m[i]] += s[i][j] == '1';
          valid = valid && c[m[i]] <= k;
        }
      }
    }
    if (valid) r = min(r, rb);
  }
  cout << r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;
/**
 * この問題は「素因数の分配の仕方は何通りあるか？」と言い換えることができます。
 * また素因数それぞれについての分け方は独立なので、全部の素因数について分配の仕方を考えて、それを全て掛け算すればよいです。
 * https://betrue12.hateblo.jp/entry/2018/09/24/020414
 */
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll p = 2; p * p <= n; p++) {
    if (n % p != 0) {
      continue;
    }
    int num = 0;
    while (n % p == 0) {
      num++;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) {
    res.push_back(make_pair(n, 1));
  }
  return res;
}

const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}
long long COM(int n, int k){
  if(n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main() {
  ll N, M;
  cin >> N >> M;
  COMinit();
  auto vec = prime_factorize(M);
  ll res = 1;
  for (auto pa : vec) {
    ll num = pa.second;
    ll tmp = COM(num + N -1, N - 1);
    res = (res * tmp) % MOD;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
 
int f(int n, int k) 
{ 
    int C[k+1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1;  // nC0 is 1 
    for (int i = 1; i <= n; i++) { 
        for (int j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main() {
  int n,m;
  cin>>n>>m;
  int ans = 0;
  if(n>=2) ans = ans + f(n,2);
  if(m>=2) ans = ans + f(m,2);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
using namespace std;
long long N;
long long K;
long long nums[200000 + 5];
vector<long long> vec;
map<long long, long long> mp;
int main() {
    ios::sync_with_stdio(0);
    cin >> N >> K;
    for (long long i = 1; i <= N; ++i) {
        cin >> nums[i];
    }
    mp.clear();
    mp[1] = 1;
    long long cur = 1, j = 1, i;
    vec.push_back(1);
    while (1) {
        long long next = nums[cur];
        ++j;
        if (mp[next] != 0) {
            i = mp[next];
            break;
        }
        else {
            mp[next] = j;
            cur = next;
            vec.push_back(cur);
        }
    }
    long long t = j - i;
    if (K <= i - 1) {
        cout << vec[K] << endl;
    }
    else {
        long long temp = K + 1 - (i - 1);
        long long ii = (temp - 1) % t + 1;
        cout << vec[i - 1 + ii - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 18680
#include<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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



int main(){

	int N,K,a,b;

	cin >> N >> K;

	rep(i,K){

	cin >> a >> b;

	if(b<=a && b<=N-a){
		if(b%3==0) cout << 3 << endl;
		if(b%3==1) cout << 1 << endl;
		if(b%3==2) cout << 2 << endl;
	}
	if(b>a && b<=N-a){
		if(a%3==0) cout << 3 << endl;
		if(a%3==1) cout << 1 << endl;
		if(a%3==2) cout << 2 << endl;
	}
	if(b>a && b>N-a){
		if((N-b+1)%3==0) cout << 3 << endl;
		if((N-b+1)%3==1) cout << 1 << endl;
		if((N-b+1)%3==2) cout << 2 << endl;
	}
	if(b<=a && b>N-a){
		if((N-a+1)%3==0) cout << 3 << endl;
		if((N-a+1)%3==1) cout << 1 << endl;
		if((N-a+1)%3==2) cout << 2 << endl;
	}

	}

      return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a;
    cin >> a ;

    //*
    if(a < 1200){
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }
    //*/
    
    //cout << max(a * b, c * d) << endl;

    return 0; 
}


Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int a,b[100];
  while(1)
  {
    scanf("%d",&a );
    if(a == 0)
    {
      break;
    }

    for(int i=0; i<a; i++)
    {
      scanf("%d",&b[i] );
    }

    sort(b,b+a);

    int c = 0;
    for(int i=1; i < a-1; i++)
    {
      c+=b[i];
    }
    printf("%d\n",c / (a-2) );
  }
}



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

int main() {
    // input from txt （提出時にこの箇所は削除すること）
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    //Write code below
    
    int n, a, b;
    
    cin >> n >> a >> b;
    
    if (n * a < b) {
        cout << n * a << endl;
    } else {
        cout << b << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
int main(){
	long long int a,b,c,n;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&n);
	long long int ans=a-b;
	if(n%2==1)ans=-ans;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
h = [int(i) for i in input().split()]
sub_flag = 0
for i in range(1,n):
    sub = h[i] - h[i-1] - sub_flag
    if sub < -1:
        print("No")
        break
    elif sub == -1:
        sub_flag = 1
    else:
        sub_flag = 0

else:
    print("Yes")

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

int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  
  int layer = 1;
  
  for (int i = 0; i < N - 1; i++) {
    if (d.at(i) > d.at(i + 1)) {
      layer++;
    }
  }
  
  cout << layer << endl;
}

Measured memory_bytes: 256
import copy
M, K =map(int,input().split())
if M == 1:
    if K == 0:
        print('0 0 1 1')
    else:
        print(-1)
elif K == 0:
    ANSL = []
    for i in range(2**M):
        ANSL.append(str(i))
        ANSL.append(str(i))
    ANS = ' '.join(ANSL)
    print(ANS)
elif K <= 2**M-1:
    LI = []
    for i in range(2**M):
        LI.append(2**M-1-i)
    LI.pop(2**M-K-1)
    CI = copy.copy(LI)
    CI.sort()
    AN = [K]+LI+[K]+CI
    ANSL =[str(s) for s in AN]
    ANS = ' '.join(ANSL)
    print(ANS)
else:
    print(-1)


Measured memory_bytes: 34612
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
ll mod = 1e9 + 7;
 
ll modpow(ll a, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int N;
	cin >> N;
	vector<ll>C(N);
	for (int i = 0; i < N; i++)cin >> C[i];
	sort(all(C));
 
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ll temp = modpow(2, N + i)*C[i];
		temp %= mod;
		ll l = N - 1 - i;
		ll temp2 = modpow(2, l) + l * modpow(2,l-1);
		temp2 %= mod;
		temp *= temp2;
		temp %= mod;
		ans += temp;
		ans %= mod;
	}
	puts(ans);
 
 
 
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define For(i, s, t) for (int i = (s); i <= (t); ++i)

const int maxn = 110;
long long col[maxn][maxn];
int x1[maxn], y1[maxn], x2[maxn], y2[maxn];
bool vis[maxn][maxn];
vector<int> ax, ay;
int n;

void dfs(int x, int y, long long val)
{
    if (x < 0 || x >= maxn || y < 0 || y >= maxn) return;
    if (vis[x][y] || col[x][y] != val) return;
    vis[x][y] = true;
    dfs(x + 1, y, val);
    dfs(x, y + 1, val);
    dfs(x - 1, y, val);
    dfs(x, y - 1, val);
}

int main()
{
    ios::sync_with_stdio(false);
    while (cin >> n && n)
    {
        ax.clear(); ay.clear();
        rep(i, n)
        {
            cin >> x1[i] >> y2[i] >> x2[i] >> y1[i];
            ax.push_back(x1[i]); ax.push_back(x2[i]);
            ay.push_back(y1[i]); ay.push_back(y2[i]);
        }
        sort(ax.begin(), ax.end());
        sort(ay.begin(), ay.end());
        ax.erase(unique(ax.begin(), ax.end()), ax.end());
        ay.erase(unique(ay.begin(), ay.end()), ay.end());
        
        rep(i, n)
        {
            x1[i] = lower_bound(ax.begin(), ax.end(), x1[i]) - ax.begin() + 1;
            x2[i] = lower_bound(ax.begin(), ax.end(), x2[i]) - ax.begin() + 1;
            y1[i] = lower_bound(ay.begin(), ay.end(), y1[i]) - ay.begin() + 1;
            y2[i] = lower_bound(ay.begin(), ay.end(), y2[i]) - ay.begin() + 1;
        }

        memset(col, 0, sizeof(col));
        rep(k, n)
            For(i, x1[k], x2[k] - 1)
                For(j, y1[k], y2[k] - 1)
                    col[i][j] |= 1LL << k;
        memset(vis, 0, sizeof(vis));
        int ans = 0;
        rep(i, maxn)
            rep(j, maxn)
                if (!vis[i][j])
                {
                    ++ans;
                    dfs(i, j, col[i][j]);
                }
        cout << ans << endl;
    }
}

Measured memory_bytes: 2084
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void gaisetu(double x1,double y1,double x2,double y2,double x3,double y3){
  //center point.and r.
  double a,b,r;
  a = ((y2-y3)*(x1*x1-x2*x2+y1*y1-y2*y2) - (y1-y2)*(x2*x2-x3*x3+y2*y2-y3*y3))
    / (2*((x1-x2)*(y2-y3)-(x2-x3)*(y1-y2)));

  b = ((x2-x3)*(x1*x1-x2*x2+y1*y1-y2*y2) - (x1-x2)*(x2*x2-x3*x3+y2*y2-y3*y3))
    / (2*((y1-y2)*(x2-x3)-(y2-y3)*(x1-x2)));

  r = sqrt((a-x1)*(a-x1) + (b-y1)*(b-y1));

  cout << fixed << setprecision(3) << a << " " <<  b << " " << r <<  endl;
}
int main(){
  //gaisetu(0.0,0.0,2.0,0.0,2.0,2.0);
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    double x1,y1,x2,y2,x3,y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    gaisetu(x1,y1,x2,y2,x3,y3);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std ;
int main()
{
	int n,x;
	int a[105];
	cin >> n >> x;
	for(int i=0;i<n;i++)
		cin >> a[i] ;
	sort(a,a+n);
	int f=0;
	for(int i=0;i<n-1;i++){
		if(x-a[i]>=0) {
		f++;x-=a[i];}
	}
	if(x-a[n-1]==0) f++;
	cout << f ;
	return 0;
}

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, m = input_to_int_map()
    a = input_to_int_tuple()

    ret = -1
    sum_a = sum(a)
    if n >= sum_a:
        ret = n - sum_a

    return ret


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 10048
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

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


Measured memory_bytes: 256
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cinll(n);

    vll d;
    for(ll i=1; i*i<=n; i++) {
        if(n%i==0)
            d.push_back(i);
    }
    ll ans=d.back()+n/d.back()-2;    
    cout<<ans<<endl;
    

}



Measured memory_bytes: 384
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
map<int,int> cnave[200005];
int a[200005],b[200005];
inline int finda(int t){
	if(a[t]==t) return a[t];
	int x=finda(a[t]);
	a[t]=x;
	return x;
}
inline int findb(int t){
	if(b[t]==t) return b[t];
	int x=findb(b[t]);
	b[t]=x;
	return x;
}
int main(){
	ios_base::sync_with_stdio(false);
	int n,p,q,i,j,x,y;
	cin>>n>>p>>q;
	for(i=0;i<n;i++) a[i]=b[i]=i;
	while(p--){
		cin>>x>>y;
		a[finda(x-1)]=finda(y-1);
	}
	while(q--){
		cin>>x>>y;
		b[findb(x-1)]=findb(y-1);
	}
	for(i=0;i<n;i++){
		finda(i);
		findb(i);
		cnave[a[i]][b[i]]++;
	}
	for(i=0;i<n;i++) cout<<cnave[a[i]][b[i]]<<" ";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 20096
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, ans = -1000000007;
    cin >> N;
    vector<vector<int>> time(N, vector<int> (10)), ben(N, vector<int> (11));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> time.at(i).at(j);
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> ben.at(i).at(j);
        }
    }

    for (int i = 1; i < 1024; i++) {
        vector<int> count(N);
        int k = i, sum = 0;
        for (int j = 0; k > 0; j++) {
            if (k & 1) {
                for (int l = 0; l < N; l++) {
                    if (time.at(l).at(j) == 1) {
                        count.at(l)++;
                    }
                }
            }
            k >>= 1;
        }
        for (int j = 0; j < N; j++) {
            sum += ben.at(j).at(count.at(j));
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
  val N = readInt()
  val A = readInts().sorted()
  val B = readInts().sorted()
  val C = readInts().sorted()

  var sum = 0L
  B.forEach { b ->
    val aNum = myBinarySearch(A.size, -1) { A[it] < b } + 1
    val cNum = C.size - myBinarySearch(-1, C.size) { b < C[it] }
    sum += aNum.toLong() * cNum
  }
  println(sum)
}

fun myBinarySearch(begin: Int, end: Int, isOk: (key: Int) -> Boolean): Int {
  var ng = begin
  var ok = end

  while (Math.abs(ok - ng) > 1) {
    val mid = (ok + ng) / 2
    if (isOk(mid)) {
      ok = mid
    } else {
      ng = mid
    }
  }

  return ok
}

fun <T> List<T>.myBinarySearch(isOk: (T) -> Boolean): Int {
  return myBinarySearch(-1, size) { index -> isOk(get(index)) }
}

fun <T> Array<T>.myBinarySearch(isOk: (T) -> Boolean): Int {
  return myBinarySearch(-1, size) { index -> isOk(get(index)) }
}


fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 104984
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n,-1);
  if (m == 0 && n == 1) {
      cout << 0 << '\n';
      return 0;
  }
  rep(i,m) {
    ll s, c;
    cin >> s >> c;
    if (a[s-1] == -1 || a[s-1] == c) {
      a[s-1] = c;
    }
    else {
      cout << -1 << '\n';
      return 0;
    }
    if (a[0] == 0 && a.size() > 1) {
      cout << -1 << '\n';
      return 0;
    }
  }
  rep(i,n) {
    if (a[i] == -1 && i == 0) {
      cout << 1;
    }
    else if (a[i] == -1) {
      cout << 0;
    }
    else {
      cout << a[i];
    }
  }
    cout << '\n';
}

Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FIILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MOD = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-7;


const int MAX = 111;
int X[MAX], Y[MAX];
double ANG[MAX];

int main()
{
    int n;
    cin >> n;
    FOR(i, 0, n)
    {
        cin >> X[i] >> Y[i];
    }
    
    FOR(i, 0, n)
    {
        int sz = 0;
        FOR(j, 0, n)
        {
            if (i == j)continue;
            int x = X[j] - X[i];
            int y = Y[j] - Y[i];
            double ang = atan2(y, x);
            ANG[sz++] = ang;
        }
        sort(ANG, ANG + sz);
        double ang = ANG[0] + 2 * PI - ANG[sz-1];
        FOR(i, 0, sz-1)
            ang = max(ang, ANG[i+1] - ANG[i]);
        
        ang -= PI;
        if (ang < 0)ang = 0;
        ang /= 2 *PI;
        cout << fixed << setprecision(15) << ang << endl;
    }
    
}


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

 
using namespace std;
 
#define ll long long
#define ul unsigned long long
#define snd second
#define fst first


int main(){
    std::ios::sync_with_stdio(false);
    int n; cin >> n;
    int minBef = n + 1;
    int cnt = 0;
    while(n--){
        int a; cin >> a;
        if(a < minBef){
            cnt++;
            minBef = a;
        }
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val a, b, c, k = Scanner.nextInt

	pw.println(if (k <= a) k else if (k <= a+b) a else a - (k-(a+b)))
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 54520