akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define mod 1000000009

int n,m;
ll modpow(ll x,ll n)
{
	ll res=1;
	while(n>0)
	{
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[3000005],R[3000005];
void make(){
	F[0] = 1;
	for(int i=1;i<3000005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<3000005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){ return F[a]*R[b]%mod*R[a-b]%mod; }
vector<P>eq,neq;
int par[3000005],ran[3000005];
void init(){ for(int i=0;i<3000005;i++) par[i] = i,ran[i] = 0; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
	x = find(x); y = find(y); if(x==y) return;
	if(ran[x] < ran[y]) par[x] = y;
	else{
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x,int y){ return find(x)==find(y); }
int main(){
	cin >> n >> m; make();
	for(int i=0;i<m;i++){
		int p,q,a;
		cin >> p >> q >> a;
		if(a == 0) eq.pb(mp(p,q));
		else neq.pb(mp(p,q));
	}
	int x = neq.size();
	ll ret = 0;
	init();
	for(int i=0;i<(1<<x);i++){
		vector<P>E = eq;
		vector<int>vi;
		for(int j=0;j<x;j++){
			if(((i>>j)&1)) E.pb(neq[j]);
		}
		set<int>se;
		map<int,int>ma;
		for(int j=0;j<E.size();j++){
			int s = E[j].fi,t = E[j].sc;
			unite(s,t);
			se.insert(s); se.insert(t);
		}
		int zan = 3*n-se.size();
		for(set<int>::iterator it = se.begin();it != se.end();++it){
			ma[find(*it)]++;
		}
		for(set<int>::iterator it = se.begin();it != se.end();++it){
			par[*it] = *it; ran[*it] = 0;
		}
		ll val = 1;
		for(map<int,int>::iterator it = ma.begin();it !=ma.end();++it){
			if( it->sc > 3) val = 0; assert(it->sc>=2);
			val = val * C(zan,3-it->sc) % mod;
			zan -= (3-it->sc);
		}
		assert(zan%3 == 0); int k = zan/3;
		val = val*F[3*k]%mod;
		val = val*modpow(modpow(6,mod-2),k)%mod*R[k]%mod;
		if(__builtin_popcount(i)%2 == 0) ret = (ret+val)%mod;
		else ret = (ret+mod-val)%mod;
	}
	cout << ret << endl;
}

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

using ll = unsigned long long;
using namespace std;

int main(void) {
    string s,t;
    cin >> s >> t;

    unordered_map<char,char> stmap, tsmap;

    bool match = true;
    for (int i = 0; i < s.size(); ++i) {
        if (stmap.find(s[i]) != stmap.end()) {
            if (stmap[s[i]] != t[i]) {
                match = false;
                // cout << "s[i]=t[i]" << s[i] << ":" << t[i] << endl;
                break;
            }
        }

        if (tsmap.find(t[i]) != tsmap.end()) {
            if (tsmap[t[i]] != s[i]) {
                match = false;
                break;
            }
        }

        stmap[s[i]] = t[i];
        tsmap[t[i]] = s[i];
    }

    cout << (match ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N=310,mod=998244353;
int n,f[N][N][N],g[N][N][N],C[N*2][N*2];
char s[N];
void add(int &x,int y){x+=y;x>=mod?x-=mod:0;}
int main(){
//	freopen("a.in","r",stdin);
	scanf("%s",s);n=strlen(s);
	g[n][0][0]=1;
	for(int i=0;i<=n;i++)C[i][0]=1;
	for(int i=1;i<=n*2;i++)for(int j=1;j<=i;j++)C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)g[n][i][j]=C[i+j][i];
	for(int i=n-1;~i;i--)for(int j=0;j<=i;j++)for(int k=0;k<=i;k++){
		g[i][j][k]=g[i+1][j][k];
		if(s[i]=='0'&&k)add(g[i][j][k],g[i][j][k-1]);
		if(s[i]=='1'&&j)add(g[i][j][k],g[i][j-1][k]);
	}
	f[0][0][0]=1;
	for(int i=0;i<=n;i++)for(int j=i;~j;j--)for(int k=i;~k;k--){
		if(j&&j+k>=2)f[i][j-1][k]|=f[i][j][k];
		if(k&&j+k>=2)f[i][j][k-1]|=f[i][j][k];
		if(i<n){if(j&&s[i]=='1')f[i+1][j-1][k+1]|=f[i][j][k];
			if(k&&s[i]=='0')f[i+1][j+1][k-1]|=f[i][j][k];
			if(j+k)f[i+1][j][k]|=f[i][j][k];
		}
		if(i+2<=n){
			if(s[i]=='0'||s[i+1]=='0') f[i+2][j+1][k]|=f[i][j][k];
			if(s[i]=='1'||s[i+1]=='1') f[i+2][j][k+1]|=f[i][j][k];
		}
	}
	int ans=0;
	for(int i=n;~i;i--)
		for(int j=i;~j;j--) {
			for(int k=i;~k;k--) {
//				printf("%d %d %d : %d %d\n", i, j, k, f[i][j][k], dp[i][j][k]);
				if( !f[i][j][k] ) continue;
				add(ans,g[i][j][k]);
				int cnt[2] = {};
				for(int l=i-1;l>=0;l--) {
					cnt[s[l]-'0']++;if(j<cnt[0]||k<cnt[1])break;
					f[l][j-cnt[0]][k-cnt[1]]=0;
				}
			}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 116796
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]==s[i+1]){
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
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...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n,d;cin >> n >> d;
    d = d*2 + 1;
    cout << (n+d-1)/d << endl;
    return 0;
}

Measured memory_bytes: 3628
s = gets.chomp.chars
i = 0
count = 0
while i < s.size
  if i % 2 == 0 
    if s[i] == "1"
      count += 1
    end
  else
    if s[i] == "0"
      count += 1
    end
  end
  i += 1
end
puts [count,s.size-count].min

Measured memory_bytes: 21844
import sys
def I(): return int(sys.stdin.readline().rstrip())

X = [I() for i in range(5)]
Y = [x % 10 for x in X if x % 10 != 0]
ans = sum(10*((x-1)//10+1) for x in X)

if len(Y) == 0:
    print(ans)
else:
    print(ans-10+min(Y))


Measured memory_bytes: 61660
import           Control.Monad
import           Text.Printf

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

getLinesInt :: Int -> IO [Int]
getLinesInt n = fmap read <$> getLines n

getInts :: IO [Int]
getInts = map (read :: String -> Int) . words <$> getLine

getDoubles :: IO [Double]
getDoubles = map (read :: String -> Double) . words <$> getLine

splitOn :: (Char -> Bool) -> String -> [String]
splitOn p s = case dropWhile p s of
    "" -> []
    s' -> w : splitOn p s'' where (w, s'') = break p s'

toInt :: [String] -> [Int]
toInt = map ((read :: String -> Int) . dropZero)

dropZero :: String -> String
dropZero s = if head s == '0' then drop 1 s else s

main :: IO ()
main = do
    s         <- getLine
    putStrLn $ let [y, m, d] = toInt $ splitOn (== '/') s in
        if func y m d > func 2019 4 30
            then "TBD"
            else "Heisei"


func y m d = y * 13 * 32 + m * 32 + d

Measured memory_bytes: 508
XS = list(open(0).read())
m = {}
for i in range(26):
    m[chr(97+i)] = 0
for x in XS:
    c = x.lower()
    if c in m:
        m[c] += 1
for k, v in m.items():
    print("{} : {}".format(k, v))


Measured memory_bytes: 5572
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int k,a,b;
  cin>>k;
  cin>>a>>b;
  srep(i,a,b+1){
    if(i%k ==0){
      print("OK");
      return 0;
    }
  }
    print("NG");
  
  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(){
	int H1, H2, M1, M2, K;
	H1, H2 >= 0 && H1, H2 <= 23;
	M1, M2 >= 0 && M1, M2 <= 60;
	int HM1, HM2;
	scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K);
	HM1 = H1 * 60 + M1;
	HM2 = H2 * 60 + M2;
	printf("%d", HM2 - HM1 - K);
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 1728
#include <iostream>

using namespace std;

int main(void){
 int K,S;
 cin >> K >> S;


 int ans = 0;

 for(int x = 0; x <= K; x++)
 {
   for(int y = 0; y <= K; y++)
   {
   int z = S - x - y;
     if(0 <= z and z <= K)
     {
     ans = ans + 1;
     }
   }
 }

 cout << ans << endl;
 
 }


Measured memory_bytes: 3604
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List

solve :: Int -> Int -> Int -> Int -> Int
solve a b c d = max (ed - st) 0
    where
        st = max a c
        ed = min b d


main :: IO ()
main = do
    [a, b, c, d] <- map read . words <$> getLine :: IO [Int]
    print $ solve a b c d


Measured memory_bytes: 508
from collections import defaultdict
n, m = map(int, input().split())
l = []
dic = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    dic[p].append(y)
    l.append([p, y])
for key, value in dic.items():
    dic[key] = {num: index+1 for index,num in enumerate(sorted(value))}
for p, y in l:
    print(str(p).zfill(6)+str(dic[p][y]).zfill(6))


Measured memory_bytes: 61880
#include<bits/stdc++.h>
using namespace std;
namespace whatever{
	int readu(){
		char ch=getchar();
		while(!isdigit(ch))
			ch=getchar();
		int value=ch-'0';
		ch=getchar();
		while(isdigit(ch)){
			value=value*10+ch-'0';
			ch=getchar();
		}
		return value;
	}
	void writeu(int n){
		if(n<10)
			putchar(n+'0');
		else{
			writeu(n/10);
			putchar(n%10+'0');
		}
	}
	void run(){
		int n=readu();
		int m=readu();
		int q=readu();
		static char s[2002][2002];
		for(int i=1; i<=n; ++i)
			gets(s[i]+1);
		static int vertex[2002][2002];
		static int edge[2][2002][2002];
		for(int i=1; i<=n; ++i)
			for(int j=1; j<=m; ++j)
				if(s[i][j]=='1'){
					++vertex[i][j];
					static pair<int, int> delta[2]={{-1, 0}, {0, -1}};
					for(int k=0; k<2; ++k)
						if(s[i+delta[k].first][j+delta[k].second]=='1')
							++edge[k][i][j];
				}
		cerr<<"clock(): "<<clock()/double(CLOCKS_PER_SEC)<<endl;
		for(int i=1; i<=n; ++i)
			for(int j=1; j<=m; ++j){
				vertex[i][j]+=vertex[i][j-1];
				edge[0][i][j]+=edge[0][i][j-1];
				edge[1][i][j]+=edge[1][i][j-1];
			}
		for(int i=1; i<=n; ++i)
			for(int j=1; j<=m; ++j){
				vertex[i][j]+=vertex[i-1][j];
				edge[0][i][j]+=edge[0][i-1][j];
				edge[1][i][j]+=edge[1][i-1][j];
			}
		cerr<<"clock(): "<<clock()/double(CLOCKS_PER_SEC)<<endl;
		while(--q!=-1){
			int x1=readu();
			int y1=readu();
			int x2=readu();
			int y2=readu();
			int vertex_result=vertex[x2][y2]+vertex[x1-1][y1-1]-vertex[x2][y1-1]-vertex[x1-1][y2];
			int edge_0_result=edge[0][x2][y2]+edge[0][x1][y1-1]-edge[0][x2][y1-1]-edge[0][x1][y2];
			int edge_1_result=edge[1][x2][y2]+edge[1][x1-1][y1]-edge[1][x2][y1]-edge[1][x1-1][y2];
			writeu(vertex_result-edge_0_result-edge_1_result);
			putchar('\n');
		}
		cerr<<"clock(): "<<clock()/double(CLOCKS_PER_SEC)<<endl;
	}
}
int main(){
	whatever::run();
}

Measured memory_bytes: 52736
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <time.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Graph{
	private:
	int V;
	vvi List;
	vi DIJ(int s){
		priority_queue<P> que;
		vi d(V,inf);
		d[s]=0;
		que.push({0,s});
		while(!que.empty()){
			P p=que.top();
			que.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(int i=0;i<List[v].size();i++){
				int F=List[v][i];
				if(d[F]>d[v]+1){
					d[F]=d[v]+1;
					que.push({-d[F],F});
				}
			}
		}
		return d;
	}
	public:
	Graph(int v){
		V=v;
		List=vvi(v);
	}
	void add_edge(int s,int t){
		List[s].push_back(t);
		List[t].push_back(s);
	}
	ll solve(int s,int t){
		vi ds=DIJ(s),dt=DIJ(t);
		sort(dt.begin(),dt.end());
		ll res=0,d=ds[t]-2;
		for(int i=0;i<V;i++){
			res+=upper_bound(dt.begin(),dt.end(),d-ds[i])-lower_bound(dt.begin(),dt.end(),d-ds[i]);
		}
		return res;
	}
};

int n,m,s,t;

int main(){
	cin>>n>>m>>s>>t;
	Graph g(n);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g.add_edge(u-1,v-1);
	}
	cout<<g.solve(s-1,t-1)<<endl;
}

Measured memory_bytes: 10840
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const ll INF = (1LL << 60);
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
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; }
/**************************************/
/******** User-defined Function *******/




/**************************************/
/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,k; cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    for(int i=k; i<n; i++){
        if(a[i]>a[i-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}
/********  Main() Ends Here *************/


Measured memory_bytes: 4784
// C++ Implementation of the above approach
#include<bits/stdc++.h>
using namespace std;

// Function to find the minimum number
// character change required

void change(string s)
{

    // Finding the length of the string
    int n = s.length();

    // To store the number of replacement operations
    int cc = 0;

    for(int i=0;i<n/2;i++)
    {

        // If the characters at location
        // i and n-i-1 are same then
        // no change is required
        if(s[i]== s[n-i-1])
            continue;

        // Counting one change operation
        cc+= 1;

        // Changing the character with higher
        // ascii value with lower ascii value

    }
    cout<<cc;

}
// Driver code
int main()
{
string s ;
cin>>s;
change((s));
return 0;
}


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



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

    vector<int> sticks;
    for(int i=0;i<n;i++) {
        int stick;
        cin >> stick;
        sticks.push_back(stick);
    }

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

    int total = 0;
    //N iterations, overall O(N^2)
    for(int largest=sticks.size() - 1;
            largest >= 0; largest--) {
        int largestLength = sticks[largest];

        //O(N)
        int left = 0;
        int right = largest - 1;
        while(left < right) {
            int cur = sticks[left] + sticks[right];
            if(cur <= largestLength) { //If too small
                left++; //Increase smallest stick
            } else {
                total += right - left;
                right--; //Decrease middle stick
            }
        }
    }

    cout << total;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int K;
    cin >> K;
    set<string> st;
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 1; j <= ((i + K >= s.size()) ? s.size() - i : K); ++j) {
            st.insert(s.substr(i, j));
        }
    }
    auto itr = st.begin();
    for (int i = 1; i < K; ++i) {
        ++itr;
    }
    cout << *itr << endl;

    return 0;
}

Measured memory_bytes: 1664
from sys import exit

a, b, c, d = map(int, list(input()))

x = ['+', '-']


def cul(x, y, z):
    if z == 0:
        return x + y
    else:
        return x - y


for i in range(8):
    op = [0, 0, 0]
    for j in range(3):
        op[j] = i >> j & 1
    if cul(cul(cul(a, b, op[0]), c, op[1]), d, op[2]) == 7:
        print(a, x[op[0]], b, x[op[1]], c, x[op[2]], d, '=7', sep='')
        exit()

Measured memory_bytes: 61992
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> V;
#define F first
#define S second
#define mod 1000000007
const ll INF=3000000000000000000;
#define MAXN 5000005
#define ull unsigned long long int
void decToBinary(ll binaryNum[],ll n) 
{  
  
    ll i = 0; 
    while (n > 0) { 
  
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
  
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1,xp=1;
    //cin>>t;
    while(t--)
    {
        ll i=0,h,j=0,n,x=0,y=0,m,k=0,l=0,r=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
        cin>>n>>x>>y;
        cout<<n/(x+y)*x+min(x,n%(x+y));

    }  

}   

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		
		//String s=sc.next();
		int a=sc.nextInt();
		//int b=sc.nextInt();
		//int c=sc.nextInt();
		//int l=s.length();
		
		
		System.out.println(((a-1)/111+1)*111);
	
		
	}	
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





Measured memory_bytes: 21204
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>

using namespace std;

int n;

char a[110];
char b[110];
char c[110];

int main()
{
	scanf("%d\n", &n);
	scanf("%s\n", a);
	scanf("%s\n", b);
	scanf("%s\n", c);
	
	int changeCount = 0;
	for (int i = 0 ; i < n ; i++)
	{
		int changes = 2;
		if (a[i] == b[i] && b[i] == c[i])
			changes = 0;			
		else if ((a[i] == b[i]) || (b[i] == c[i]) || (a[i] == c[i]))
			changes = 1;
		else
			changes = 2;
			
		changeCount = changeCount + changes;
			
	}
	
	printf("%d\n", changeCount);

	return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    ll min_cost;
    if( a+b < 2*c){
        min_cost = a*x + b*y;
    }else{
        if(x == y) min_cost = x*c*2;
        else if(x > y){
            min_cost = y*c*2;
            if(a > 2*c) min_cost += 2*c*(x-y);
            else min_cost += a*(x-y);
        }else{
            min_cost = x*c*2;
            if(b > 2*c) min_cost += 2*c*(y-x);
            else min_cost += b*(y-x);
        }
    }
    cout << min_cost << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const ll MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
char text[MAXN];
int num[MAXN];

int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d%d", &n, &m);
    printf("%d", 6 - n - m);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

int main() {
    int n; cin >> n;
    vector<int> s(n);
    REP(i,n) cin >> s[i];
    int q; cin >> q;
    vector<int> t(q);
    REP(i,q) cin >> t[i];
    int ans = 0;
    REP(i,q) {
        REP(j,n) {
            if(t[i]==s[j]) {
                ans ++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3144
N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
                if L[i] < L[j]+L[k] and L[j] < L[i]+L[k] and L[k] < L[i]+L[j]:
                    ans += 1
print(ans)

Measured memory_bytes: 9204
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    long long a[n][m], b[m][l], c;
    for(int i=0; i<n; ++i) {
        for(int j=0; j<m; ++j) {
            cin >> a[i][j];
        }
    }
    for(int i=0; i<m; ++i) {
        for(int j=0; j<l; ++j) {
            cin >> b[i][j];
        }
    }
    for(int i=0; i<n; ++i) {
        for(int j=0; j<l; ++j) {
            c=0;
            for(int k=0; k<m; ++k) {
                c+=a[i][k]*b[k][j];
            }
            if(j) cout << " ";
            cout << c;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<pll>
#define vl vector<ll>
#define f first
#define s second
#define N 50000
#define pb push_back
#define MAP map<ll,ll>
#define MAPs map<<ll,sl>
#define MAPv map<ll,vl>
#define  mset(x,val) memset(x,val,sizeof(x))
#define mod 1000000007
#define foo(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,a,b) for(ll i=(a);i>=(b);i--)
#define FOR(i,v) for(auto &(i):(v))
#define sl set<ll>
#define sll set<pll>
#define ub upper_bound
#define lb lower_bound
using namespace std;

const ll   INF = 0x7f7f7f7f7f7f7f7f;
const ll NINF = -INF;
const ll MAXN  = 1e+6 + 8;

int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
//<<-----Declare Variable Here------->>//
ll n, a[200005];
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN() {
    cin >> n;
    foo(i, 0, n - 1) cin >> a[i];

    ll cst = 1000, stk = 0;
    foo(i, 0, n - 2) {
        if (a[i] < a[i + 1]) {
            ll tmp = cst / a[i];
            stk += tmp;
            cst -= tmp * a[i];
        }
        else if (a[i] > a[i + 1]) {
            cst += stk * a[i];
            stk = 0;
        }
    }

    cst += stk * a[n - 1];
    cout << cst << "\n";
}

int main() {
    fastio;
    ll t = 1;
    // cin>>t;
    while (t--) {
        MAIN();
    }

    // #ifndef ONLINE_JUDGE
    // cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    // #endif
}

Measured memory_bytes: 3648
import java.io.IOException;
import java.util.Scanner;

public class Main {
	/**
	 * Main method.
	 */
	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(System.in);
		
		int N = s.nextInt();
		
		boolean check = false;
		for (int i = 0; i < N; i++) {
			String color = s.next();
			if (color.equals("Y")) {
				check = true;
				break;
			}
		}
		
		System.out.println(check ? "Four" : "Three");
 
	}
}

Measured memory_bytes: 21716
a,b,c,k=map(int,input().split())
ans=0

if(k<=a):
    ans+=k
    k=0
else:
    ans+=a
    k-=a

if(k<=b):
    k=0
else:
    k-=b

if(k>0):
    ans-=k
    k=0

print(ans)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define ll long long

using namespace std;

set<string>q;
set<string>a[10];

int s[10];

int main()
{

    int n;
    string ss;
    scanf("%d", &n);
    while(n--)
    {
        cin>>ss;
        if(ss[0] == 'M')
            a[0].insert(ss);
        else if(ss[0] == 'A')
            a[1].insert(ss);
        else if(ss[0] == 'R')
            a[2].insert(ss);
        else if(ss[0] == 'C')
            a[3].insert(ss);
        else if(ss[0] == 'H')
            a[4].insert(ss);

    }
    ll sum = 0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                sum+=1ll*(a[i].size()*a[j].size()*a[k].size());
            }
        }
    }
    printf("%lld\n", sum);
    return 0;

}


Measured memory_bytes: 9600
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define MOD1 998244353
#define endl "\n"
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define forn1(i, n) for(int i = 1; i <= int(n); i++)
#define int ll
using namespace std;
typedef long double ld;
typedef long long ll;
typedef set <int> si;
typedef multiset <int> msi;
typedef unordered_set <int> usi;
typedef unordered_multiset <int> umsi;
typedef pair<int,int> pairs;
typedef vector <int> VI;
typedef map<int,int> mii;
typedef multimap <int,int> mmii;
typedef unordered_map <int,int> umii;
typedef unordered_multimap<int,int> ummii;
double pi = 2 * acos(0.0);
inline int two(int n) { return 1 << n; }
struct cmp{
    /////call by set<pair<int, int>, cmp>
    bool operator() (const pair<int, int>& a, const pair<int, int>& b) const{
        int lena= a.second - a.first + 1;
        int lenb = b.second - b.first + 1;
        if(lena == lenb) return a.first < b.first;
        return lena > lenb;
    }
};
bool isPrime(int n) { 
    if (n <= 1)  return false; if (n <= 3)  return true; if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; 
    return true; 
}


signed main()  {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif 
    //
    int t=1;
    //cin>>t;
    while(t--) {
        int n,m;
        cin>>n>>m;
        cout << n*m << endl;

    }
    
    return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[(int)(N - 1)];
        int[] B = new int[(int)(N)];
        
        for(int i = 0 ; i < N - 1 ; i++){
                A[i] = sc.nextInt();
                B[A[i] - 1] = B[A[i] - 1] + 1; 
        }
        for(int i = 0 ; i < N ; i++){
            System.out.println(B[i]);
        
        }        
     }
}

Measured memory_bytes: 52464
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;

int v[2][110000];
int main()
{
	int n,x;
	scanf("%d",&n);
	memset(v,0,sizeof(v));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		v[i%2][x]++;
	}
	
	int mx[2],sx[2],mid[2],sid[2];
	mx[0]=mx[1]=sx[0]=sx[1]=0;
	for(int t=0;t<=1;t++)
	{
		for(int i=1;i<=100000;i++)
		{
			if(v[t][i]>mx[t])
			{
				sx[t]=mx[t];sid[t]=mid[t];
				mx[t]=v[t][i];mid[t]=i;
			}
			else if(v[t][i]>sx[t])
			{
				sx[t]=v[t][i];sid[t]=i;
			}
		}
	}
	if(mid[0]==mid[1])printf("%d\n",n-max(sx[0]+mx[1],sx[1]+mx[0]));
	else printf("%d\n",n-mx[0]-mx[1]);
	return 0;
}

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

int n,W;
LL dp[100005];

int main() {
	scanf("%d%d",&n,&W);
	memset(dp,-1,sizeof(dp));
	dp[0] = 0;
	LL ret = 0;
	for (int i=0; i<n; i++) {
		int w,v;
		scanf("%d%d",&w,&v);
		for (int j=W; j>=w; j--) {
			if (dp[j-w] != -1) {
				dp[j] = max(dp[j],dp[j-w]+v);
				ret = max(dp[j],ret);
			}
		}
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 1024
import itertools
N,M,X = list(map(int, input().split()))
C = [0 for i in range(N)]
A = [[0 for j in range(M)] for j in range(N)]
for i in range(N):
    A_ = list(map(int, input().split()))
    C[i] = A_[0]
    for j in range(M):
      A[i][j] = A_[j+1]
      
def check(books):
    algos_point = [0]*M
    for i in books:
        for j in range(M):
            algos_point[j] = algos_point[j] + A[i][j]
    for j in range(M):
        if algos_point[j] < X:
            return False
    return True

def cost(books):
    val = 0
    for i in books:
        val = val + C[i]
    return val
  
combi = []
for i in range(1,N+1):
    combi += list(itertools.combinations(list(range(N)), i))

vals = []
for c in combi:
  if check(c):
    vals.append(cost(c))
        
if vals == []:
  print(-1)
else:
  print(min(vals))


Measured memory_bytes: 9520
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String s= sc.nextLine();
		long lng = Long.parseLong(s);
		String[] str=s.split("");
		int top=Integer.parseInt(str[0]);
		int answer=0;

		for(int i=0;i<str.length;i++){
			int n=Integer.parseInt(str[i]);
			answer=answer+n;
		}
		if(answer<(str.length-1)*9+top-1){
			answer=(str.length-1)*9+top-1;
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 21972
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

struct Info{
	Info(ll arg_value,int arg_loc){
		value = arg_value;
		loc = arg_loc;
	}
	bool operator<(const struct Info &arg) const{
			return value < arg.value;
	};
	ll value;
	int loc;
};

/*
 * ???????´?????????????????????????????????????0
 * ??´??????????????????????????????????????????????????£???????????£???
 */

int main(){

	int N;
	scanf("%d",&N);

	ll sum = 0,tmp;
	priority_queue<Info> Q;

	Q.push(Info(0,0));

	for(int i = 1; i <= N; i++){
		scanf("%lld",&tmp);
		sum += tmp;
		Q.push(Info(sum,i));
	}

	ll pre = -1;
	int maximum = 0,min_index = -1,max_index = -1;

	while(!Q.empty()){
		if(pre == Q.top().value){
			min_index = min(min_index,Q.top().loc);
			max_index = max(max_index,Q.top().loc);
		}else{
			maximum = max(maximum,max_index - min_index);
			max_index = min_index = Q.top().loc;
		}

		pre = Q.top().value;
		Q.pop();
	}
	if(min_index != max_index){
		maximum = max(maximum,max_index - min_index);
	}

	printf("%d\n",maximum);

	return 0;
}

Measured memory_bytes: 6496
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int ans=0,n,d;
signed main(){
	cin>>n>>d;
	for(int i=0;i<n;i++){
		int x,y;cin>>x>>y;
		ll val=(ll)x*x+(ll)y*y;
		long double vall=(long double)sqrt(val);
		if(vall<=d){ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int INF = 1<<29;


int main(){
  int n,m,x,y; cin >> n >> m;
  vector<vector<int> > g(n);
  vector<int> deg(n);
  for(int i=0; i < m; ++i) {
    cin >> x >> y; --x; --y;
    g[x].push_back(y);
    ++deg[y];
  }

  queue<int> que;
  for(int i=0; i < n; ++i) if(deg[i] == 0) que.push(i);

  vector<int> ans;
  while(que.size()) {
    int v = que.front(); que.pop();
    for(int nv : g[v]) {
      --deg[nv];
      if(deg[nv] == 0) que.push(nv);
    }
    ans.push_back(v+1);
  }
  for(int v : ans) cout << v << '\n';
  return 0;
}


Measured memory_bytes: 3136
N = int(input())
A = ([int(x) for x in input().split()])
B = ([int(x) for x in input().split()])
C = ([int(x) for x in input().split()])

Sat = 0
j = 0
for i in A:
    Sat += B[i-1]
    if (i - j == 1) & (j != 0):
        Sat += C[j-1]
    j = i

print(Sat)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;cin>>n>>k;
  int res=0;
  rep(i,n){int a;cin>>a;res+=min(k-a,a);}
  cout<<res*2<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

ll a,b,c,k;

ll solve() {
	if(k%2==0) return a-b; else return b-a;
}

void run() {
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	printf("%lld\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define MAX_NUM 50001
#include <iomanip>
#include <string>
#include <utility>
#include <map>
using namespace std;



bool isuseful(long long x)
{
    int a[8]={0},temp=x;
    while(x)
    {
        temp=x%10;
        x/=10;
        a[temp]++;
        if(a[3]&&a[5]&&a[7])
            break;

    }
            if(a[3]&&a[5]&&a[7])
            return true;
            else
    return false;


}
long long getwei(long long x)
{
    long long num=0;
    while(x)
    {

    x/=10;
    num++;
    }
    return num;
}
long long my_pow(long long x,long long wei)
{
    long long num=1;
    while(wei)
    {
        num*=x;
        wei--;
    }
    return num;
}
int main()
{
    long long X;
    cin>>X;
    queue<long long> qu;
    qu.push(3);
        qu.push(5);
            qu.push(7);
long long num=0;
long long new_num=0;
  while(new_num<=X*10)
  {
      long long u=qu.front();
      qu.pop();
      long long wei=getwei(u);

      for(int i=3;i<=7;)
      {
        new_num=u+(my_pow(10,wei)*i);
        qu.push(new_num);


        if(isuseful(new_num) && new_num<=X)
            num++;
        if(i==3)
            i=5;
        else if(i==5)
            i=7;
        else
            i=8;
      }
  }

    cout<<num;

}



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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N;
  cin >> N;
  double ans = 0;
  if (N%2==0) {
    ans = 0.5;
  } else {
    ans = (double)(N/2+1) / N;
  }
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void) {
	ll n, a, ans = 1e18;

	cin >> n;

	for (a = 1; a * a <= n; a++) {
		if (n % a == 0) {
			ans = min(ans, a + n / a - 2);
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main() {
	int X, Y;
	string result = "No";
	cin >> X >> Y;

	for (int i = 0; i <= X; i++) {
		if (2 * i + 4 * (X - i) == Y) {
			result = "Yes";
			break;
		}
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<random>
using namespace std;


int main(){

  string a[3];
  cin >> a[0] >> a[1] >> a[2];

  cout << 'A' << a[1][0] << 'C' << endl;


  return 0;
}














// EOF


Measured memory_bytes: 256
def solve():
    H,W = map(int, input().split())
    N = int(input())
    A = map(int, input().split())
    i,j = 0,0
    delta = 1
    ret = [[0]*W for _ in range(H)]
    for k,a in enumerate(A):
        while a > 0:
            ret[i][j] = k+1
            a -= 1
            if 0 <= j+delta < W:
                j += delta
            else:
                i += 1
                delta = delta*(-1)
                
    print('\n'.join([' '.join(map(str, r)) for r in ret]))
    
solve()

Measured memory_bytes: 3568
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  if(!v.empty()) {
    std::copy(v.begin(), v.end() - 1, std::ostream_iterator<T>(out, " "));
    out << v.back();
  } else {
    out << "";
  }
  return out;
}

int bubblesort(std::vector<int> &xs) {
  int len = xs.size();
  int cnt_swap = 0;
  bool flag = true;
  while(flag) {
    flag = false;
    for(int i = len - 1; i >= 1; --i) {
      if(xs[i] < xs[i - 1]) {
        std::swap(xs[i], xs[i - 1]);
        flag = true;
        cnt_swap++;
      }
    }
  }
  return cnt_swap;
}

int main(void) {
  int n;
  std::cin >> n;

  std::vector<int> xs;
  int x;
  for(int i = 0; i < n; ++i) {
    std::cin >> x;
    xs.push_back(x);
  }

  int cnt = bubblesort(xs);

  std::cout << xs << std::endl;
  std::cout << cnt << std::endl;

  return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s.at(i);
    }
    int m;
    cin >> m;
    vector<string> t(m);
    for (int i = 0; i < m; i++) {
        cin >> t.at(i);
    }

    int max = 0;
    for (int i = 0; i < n; i++) {
        string card = s.at(i);
        int cnt = 0;
        for (int j = 0; j < n; j++) {
            if (card == s.at(j)) cnt++;
        }
        for (int j = 0; j < m; j++) {
            if (card == t.at(j)) cnt--;
        }
        if (cnt > max) max = cnt;
    }

    cout << max << endl;
}


Measured memory_bytes: 256
use std::io::*;

fn main() {
	let input = {
		let mut buf = vec![];
		stdin().read_to_end(&mut buf);
		unsafe { String::from_utf8_unchecked(buf) }
	};

	let (d, c) = {
		let mut iter = input.split_whitespace().map(|s| s.parse::<u32>().unwrap());

		(iter.next().unwrap(), iter.next().unwrap())
	};

	println!("{}", d * c);
}



Measured memory_bytes: 5016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    string s;
    int x, y;
    cin >> s >> x >> y;
    bool turn = 0, chk = 1;
    int xcnt = 0, ycnt = 0, tcnt = 0, nx = 0;
    vector<int> vecx, vecy;
    rep(i, 0, s.size()) {
        if (s[i] == 'F') {
            if (turn) {
                ycnt++;
            } else {
                xcnt++;
            }
        } else {
            if (turn) {
                turn = 0;
                vecy.push_back(ycnt);
                ycnt = 0;
            } else {
                turn = 1;
                vecx.push_back(xcnt);
                xcnt = 0;
            }
            tcnt++;
        }
    }
    if (xcnt) vecx.push_back(xcnt);
    if (ycnt) vecy.push_back(ycnt);
    x -= vecx[0];
    vecx.erase(vecx.begin());
    sort(vecx.begin(), vecx.end(), greater<int>());
    sort(vecy.begin(), vecy.end(), greater<int>());
    for (int nx : vecx) {
        if (x >= 0) {
            x -= nx;
        } else {
            x += nx;
        }
    }
    for (int ny : vecy) {
        if (y >= 0) {
            y -= ny;
        } else {
            y += ny;
        }
    }
    if (y == 0 && x == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 3688
#include <stdio.h>

int main(void)
{
	int a,b,c,d,sum;
	scanf("%d\n%d\n%d\n%d",&a,&b,&c,&d);
	
	if(a>b){
		if(c>d){
			sum=b+d;
		}else{
			sum=b+c;
		}
	}else{
		if(c>d){
			sum=a+d;
		}else{
			sum=a+c;
		}
	}
	
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;
use std::collections::*;
use std::cmp::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut candidates = HashMap::new();
    let n: usize = read();
    for _ in 0..n {
        let s: String = read();
        let counter = candidates.entry(s).or_insert(0);
        *counter += 1;
    }
    let m: usize = read();
    for _ in 0..m {
        let s: String = read();
        let counter = candidates.entry(s).or_insert(0);
        *counter -= 1;
    }
    let mut ans = 0;
    for v in candidates.values() {
        ans = max(ans, *v);
    }
    println!("{}", ans);
}

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

int n, a[100005], h, w;

int main(void){
  cin >> h >> w >> n;
  for(int i = 0; i < h * w; i++){
    cin >> a[i];
  }
  int ans[1000][1000];
  int c = 0;
  int gyo = 0, retsu = 0;
  while(c < h * w){
    int col = 0;
    int sum = 0;
    while(true){
      if(sum > min(c, h * w - 1)){
	break;
      }
      sum += a[col];
      col++;
    } 
    ans[retsu][gyo] = col;
    if(gyo < w - 1 and retsu % 2 == 0){
      gyo++;
    }
    else if(gyo == w - 1 and retsu % 2 == 0){
      retsu++;
    }
    else if(gyo > 0 and retsu % 2 == 1){
      gyo--;
    }
    else if(gyo == 0 and retsu % 2 == 1){
      retsu++;
    }
    c++;
  }

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << ans[i][j];
      if(j == w - 1){
	cout << "" << endl;
      }
      else{
	cout << " ";
      }
    }
  }
}


Measured memory_bytes: 768
n = int(input())
lis = list(map(int, input().split()))
ans = 0

for i in range(n):
  con = 0
  if lis[i] % 2 == 0:
    x = lis[i]
    while x % 2 == 0:
      x = int(x / 2)
      con += 1
  ans += con   

print(ans)

Measured memory_bytes: 9996
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;
const int INF = (1 << 30);

int main(){

    int N, M;
    cin >> N >> M;

    int setSize = (1 << N);
    vector<int> minCost(setSize, INF);
    minCost[0] = 0;

    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;

        int key = 0;
        int c;
        for(int i = 0; i < b; i++){
            cin >> c;
            c--;
            key += (1 << c);
        }
        for(int i = 0; i < setSize; i++){
            if(minCost[i] == INF){
                continue;
            }
            int nextState = (i | key);
            int tempCost = minCost[nextState];
            minCost[nextState] = min(tempCost, minCost[i] + a);
        }
    }

    if(minCost[setSize - 1] == INF){
        cout << -1 << endl;
    }
    else{
        cout << minCost[setSize - 1] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256