akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (b), _a = (a); i >= _a; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = (n) - 1; i >= 0; i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define all(ar) ar.begin(), ar.end()
#define sz(x) ((long long)x.size())
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define trace2(x, y)            cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)         cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)      cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)   cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;

ll const INF=1LL<<60LL;
double const pi=3.14159265358979323846264338327950; 

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

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

ll modpower(ll base,ll power,ll mod){
	ll res=1;
	while(power){
		if(power%2){
			res=(res*base)%mod;
			power--;
		}
		base=(base*base)%mod;
		power/=2;
	}
	return res;
}
ll const MAX=1000001;

void solve(){
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double e=(double)(m*pi)/360;
	double alpha=(double)((double)((double)pi)/((double)6))*h+e;
	double beta=(double)((double)((double)pi)/((double)30))*m;
	double angle=alpha-beta;
	//debug(angle/pi*180);
	double ans=(double)sqrt((double)(a)*(a)+(double)(b)*(b)-(double)(((double)2)*a*b*cos(angle)));
	cout<<ans<<endl;
}
    
int main () 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(30);
    #ifndef ONLINE_JUDGE
    freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
 
    }
 
    return 0;   
}

Measured memory_bytes: 4268
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=200000 +117;
const int MM=200000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
int par[NN]={};
int fa[NN]={};
int a[NN][2]={};
struct node{
	int x,v[2];
	node(int x_=0){
		x=x_,v[0]=a[x_][0],v[1]=a[x_][1];
	}
};
struct cmp{
	bool operator () (node a,node b){
		return (LL)a.v[1]*b.v[0]>(LL)a.v[0]*b.v[1];
	}
};
priority_queue<node,vector<node>,cmp> q;

LL ans=0;
int getfa(int x){
	return x==fa[x]?x:fa[x]=getfa(fa[x]);
}
void link(int x){
	int y=getfa(par[x]);
	ans+=(LL)a[y][1]*a[x][0];
	a[y][0]+=a[x][0];
	a[y][1]+=a[x][1];
	fa[x]=y;
}
int main(){
	//open();
	n=read();
	for(int i=2;i<=n;++i){
		par[i]=read();
	}
	for(int i=1;i<=n;++i){
		a[i][read()]++;
	}
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1;i<=n;++i){
		q.push(node(i));
	}
	while(!q.empty()){
		int x=q.top().x;
		q.pop();
		if(fa[x]!=x||x==1)continue;
		link(x);
		q.push(node(getfa(x)));
	}
	printf("%lld\n",ans);
	close();
	return 0;
}

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

int main()
{
	stack<int> s;
	int order;
	while (cin >> order)
	{
		if (order == 0)
		{
			cout << s.top() << endl;
			s.pop();
		}
		else
		{
			s.push(order);
		}
	}

	return 0;
}

Measured memory_bytes: 1204
def solve():
  N = int(input())
  H = list(map(int, input().split()))
  dp = [float('inf')]*N
  dp[0]=0
  for i in range(N):
    if i+1<N:
      dp[i+1] = min(dp[i+1],dp[i]+abs(H[i+1]-H[i]))
    if i+2<N:
      dp[i+2] = min(dp[i+2],dp[i]+abs(H[i+2]-H[i]))
  ans = dp[N-1]
  return ans
print(solve())

Measured memory_bytes: 85680
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;


int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	int x = 0, y = 0;
	for (int i = 0; i < n; i++){
		if (i % 2 == 0){ x += a[i]; }
		else{ y += a[i]; }
	}
	cout << x - y;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n-1;i>s;i--)
#define rep_re(i,s,n)for(ll i = n-1;i>=s;i--)
ll MOD = 1e9 + 7;

ll a[300001] = {};
ll Pow(ll n, ll p) {
	if (p == 0)return 1;
	if (p == 1)return n;
	ll t = Pow(n, p / 2);
	if (p & 1) return (t * t % MOD) * n % MOD;
	else return t * t % MOD;
}
int main() {
	ll n; cin >> n;
	rep(i, 0, n)cin >> a[i];

	ll ans = 0;
	rep(i, 0, 60) {
		ll mask = 1ll << i;

		ll z = 0, o = 0;
		rep(i, 0, n) {
			ll v = mask & a[i];
			if (v == 0) {
				z++;
			}
			else {
				o++;
			}
		}
		ll p = z * o % MOD;
		ans = (ans + (Pow(2, i) * p) % MOD) % MOD;
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long int li;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<float, float> ff;
typedef pair<double, double> dd;
typedef unsigned int ui;
typedef vector<ii> vii;
typedef vector<ff> vff;
typedef set<int> si;
typedef set<lli> slli;
typedef vector<lli> vlli;
typedef long long ll;
typedef long long ll;
typedef vector<ll> vll;
typedef unsigned long long int ulli;
#define MOD 1000000007
#define INF (unsigned)(~0)>>1
typedef pair<int, ii> iii;
void arr_int(int* given_arr, int n){
  for(int i=0;i<n;i++)
    scanf("%d", &given_arr[i]);
  return;
}
int gcd(int a, int b){if(b==0) return a; else return gcd(b, a%b);}
void solve();
int main(int argc, char const *argv[]){
  solve();
  return 0;
}
void solve(){
  int N;
  int P;
  scanf("%d %d", &N, &P);
  string s;
  cin>>s;


  if(P == 2 || P==5){
    lli ans = 0;
    for(int i=0;i<N;i++){
      if((s[i] - '0')%P==0)ans+= i+1;
    }
    printf("%lld\n", ans);
    return;
  }


  reverse(s.begin(), s.end());
  lli arr[N];
  lli mul = 1;
  lli ans = 0;
  for(int i=0;i<N;i++){
    arr[i] = ((s[i] - '0')%P * (mul)%P)%P;
    mul *= 10;
    mul %=P;
  }

  lli mod[P] = {0};
  lli cumSum = 0;
  for(int i=0;i<N;i++){
    cumSum += arr[i]%P;
    mod[cumSum%P]++;
  }
  for(int i=0;i<P;i++){
    if(mod[i]>1)
      ans += (mod[i] )* (mod[i]-1)/2;
  }
  ans  += mod[0];
  printf("%lld\n", ans);
}


Measured memory_bytes: 2180
#include<stdio.h>

#define nMIN 2
#define nMAX 200000
#define RtMIN 1
#define RtMAX 1000000000


int main(){
int n[nMAX],Time,i,max=0,sub;

scanf("%d",&Time);
if(RtMIN<=Time&&Time<=RtMAX){
for(i=0;i<Time;i++){
scanf("%d",&n[i]);
//if(nMIN>n[i]||n[i]>nMAX)exit(1);
}
max=n[i-1];
sub=n[i-1]-n[i-2];
for(i=Time-2;i>=0;i--){

if(max<n[i]&&i!=0){
max=n[i];
}
if(sub<max-n[i]&&n[i]!=max){
sub=max-n[i];
}
}
}
 else exit(1);

printf("%d\n",sub);
return 0;
}



Measured memory_bytes: 2564
import Control.Arrow
import Data.Ratio
import qualified Data.Map as M

main = do
  [_,ma,mb] <- map read . words <$> getLine :: IO [Int]
  abcs <- map (map read . words) . lines <$> getContents :: IO [[Int]]
  print $ maybe (-1) id (mixing ma mb abcs)

mixing ma mb = M.lookup (ma % mb) . M.mapKeysWith min (uncurry (%)) . M.deleteMin . foldl (dp ma mb) (M.singleton (0,0) 0)

dp ma mb acc [a,b,c] = M.unionWith min acc $ M.mapKeysMonotonic ((+a) *** (+b)) $ M.map (+c) acc

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

int main(){
  int n;
  cin >> n;
  vector<string>word(n);
  for(int i = 0; i < n; i++){
    cin >> word.at(i) ;
  }
  bool a = true;
  for (int j = 0; j < n; j++){
    if(a){
      
    for (int k = j+1; k < n; k++){
      if(word.at(j) == word.at(k)){
        a = false;
        break;
      }
    }
    }
  }
  if(a){
    for (int i = 0; i < n-1; i++){
      if(word.at(i).at(word.at(i).size()-1) != word.at(i+1).at(0)){
        a = false;
        break;
      }
    }
  }
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() { 
  int x, y;cin >> x >> y;
  if (x == y) cout << "0\n";
  else if (x < y) cout << min(y - x, abs(y + x) + 1) << '\n';
  else cout << min(abs(x + y) + 1, x - y + 2) << '\n';
}

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

int main() {
  int N;
  string result;
  cin >> N;
  vector<char>S(N);

  for (int i = 0; i < N; i++){
    cin >> S.at(i); //入力の受付

    if (S.at(i) == 'Y'){
      result = "Four"; //Yが見つかればresultに代入
      break;
    }
    else{
      result = "Three"; // Yが見つからなければresultにThreeを代入
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<bitset>
#include<algorithm>
#include<climits>
#include<vector>
#include<deque>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> P;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define dump(a) rep(i,a.size()){ cout<<a[i]<<" "; } cout<<endl;
#define dumparr(a,n) rep(i,n){ cout<<a[i]<<" "; } cout<<endl;
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define FINF DBL_MAX/3
#define EPS 1e-7
#define OUT1(n1) cout<<n1<<endl
#define OUT2(n1,n2) cout<<n1<<" "<<n2<<endl
#define OUT3(n1,n2,n3) cout<<n1<<" "<<n2<<" "<<n3<<endl
#define OUT4(n1,n2,n3,n4) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<endl
#define OUT5(n1,n2,n3,n4,n5) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<endl
#define OUT6(n1,n2,n3,n4,n5,n6) cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<" "<<n6<<endl
#define OUT(n, ...) OUT##n(__VA_ARGS__)

/* 隠れた制約を見つける
 * 符号化
 *
 */

int main(){
  ll n;
  cin>>n;
  string s1,s2;
  cin>>s1>>s2;
  const ll M = 1e9+7;

  ll i = 0;
  string s = "";
  while(i<n) {
    if(s1[i]==s2[i]) {
      s.append("b");
      i += 1;
    } else if (s1[i]==s1[i+1] && s2[i]==s2[i+1]) {
      s.append("a");
      i += 2;
    }
  }
  /* OUT1(s); */
  ll c = (s[0]=='b') ? 3 : 6;
  repl(i,1,s.length()){
    if(s[i-1]=='a') { if(s[i]=='a') c = (c*3)%M;
    } else {
      if(s[i]=='b') c = (c*2)%M;
      else c = (c*2)%M;
    }
  }
  OUT1(c);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,m;
    cin>>n>>m;
    ll x[n],y[m];
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<m;i++)cin>>y[i];
    ll xans=0,yans=0;
    for(ll i=1;i<n;i++){
        xans+=(x[i]-x[i-1])*((i*(n-i))%MOD);
        xans%=MOD;
    }
    for(ll i=1;i<m;i++){
        yans+=(y[i]-y[i-1])*((i*(m-i))%MOD);
        yans%=MOD;
    }
    cout<<(xans*yans)%MOD<<endl;
}


Measured memory_bytes: 1792
import numpy as np

N,D = list(map(int,input().split()))
X = []
for n in range(N):
    X.append(list(map(int,input().split())))
#N個のリスト入力を受け取る

vec = np.array(X)
#listをnumpyの行列型に変換
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        dist = np.linalg.norm(vec[i]-vec[j])
        if dist.is_integer():
            cnt += 1
print(cnt)

Measured memory_bytes: 12424
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/arc071_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  map<char, int> m;
  rep(i, N) {
    map<char, int> t;
    string s;
    cin >> s;
    rep(j, s.size()) { t[s[j]]++; }
    if (i == 0) {
      m = t;
    } else {
      map<char, int> n;
      for (auto kv : t) {
        if(m[kv.first]) {
          n[kv.first] = min(kv.second, m[kv.first]);
        }
      }
      m = n;
    }
  }

  for (auto kv: m) {
    rep(i, kv.second) { cout << kv.first; }
  }
}

Measured memory_bytes: 3648
words = lambda t : list(map(t, input().split()))
s = input()
t = input()

dict = {}
for i in range(len(s)):
    c = s[i]
    if c not in dict:
        dict[c] = []
    dict[c].append(i)

for k,v in dict.items():
    dict[k] = sorted(v)

#print(dict)

from bisect import bisect_right
def find_min_t(cur, c):
    k = bisect_right(dict[c], cur)
    if k >= len(dict[c]):
        return dict[c][0]
    else:
        return dict[c][k]

cur = -1
ans = 0
succeed = True
for c in t:
    if c not in dict:
        succeed = False
        break
    i = find_min_t(cur, c)
    #print(c, i, cur)
    if i <= cur:
        ans += len(s)
    cur = i

if succeed:
    print(ans + cur + 1)
else:
    print(-1)


Measured memory_bytes: 47068
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int n, m;
	int X, Y;
	int x[100], y[100];
	int z;
	int xmax=-100,ymin=100;

	scanf("%d %d", &n, &m);
	scanf("%d %d", &X, &Y);
	for (int i = 0; i < n; i++){
		scanf("%d", &x[i]);
		if (x[i]>xmax){
			xmax = x[i];
		}
	}
	for (int i = 0; i < m; i++){
		scanf("%d", &y[i]);
		if (y[i]<ymin){
			ymin = y[i];
		}
	}
	if (xmax < X){
		xmax = X;
	}
	if (ymin>Y){
		ymin = Y;
	}
	if ((ymin - xmax) > 0){
		printf("No War\n");
	}
	else{
		printf("War\n");
	}
	return 0;
}


Measured memory_bytes: 256
from pprint import pprint

n,m,q = map(int, input().split())

ql = [list(map(int,input().split())) for _ in range(q)]

#print(n)
#print(m)
#print(q)
#pprint(ls)

masterlist = []
minilist = [0] * n
i = 0


def saiki(before_a,i,minilist):
    if i > n-1:
        masterlist.append([minilist[j] for j in range(n)])
        return
    for Ai in range(before_a,m+1):
        minilist[i] = Ai
        saiki(Ai,i+1,minilist)

#for before_a in range(1,m+1):
#    saiki(before_a,where,minilist)

before_a = 1
saiki(before_a,i,minilist)

#pprint(masterlist)
#pprint(ql)

dmax = 0

for a_mini in masterlist:
    dtemp = 0
    for ql_mini in ql:
        if a_mini[ql_mini[1]-1] - a_mini[ql_mini[0]-1] == ql_mini[2]:
            dtemp += ql_mini[3]
        else:
            pass
    if dtemp >= dmax:
        dmax = dtemp

print(dmax)

Measured memory_bytes: 28432
n = int(input())
s = list(map(int, input().split()))
count = 0
while True:
    flag = False
    for i in range(n):
        if s[i]%2 != 0 or s[i] == 0:
            flag = True
            break
    if flag:
        break
    for i in range(n):
        s[i] = s[i]/2
    count += 1


print(count)


Measured memory_bytes: 3060
#include<cstdio>
#include<vector>
using namespace std;

bool f[55566];
vector<int>v[11];

int main() {
	for(int i=2;i*i<=55555;i++) {
		if (f[i]) continue;
		for(int j=i*i;j<=55555;j+=i)
			f[j] = true;
	}
	for(int i=0;i<5;i++) v[i].clear();
	for(int i=2;i<=55555;i++)
		if (!f[i]) v[i%5].push_back(i);
	
	//for(int i=0;i<5;i++) printf("%d\n", (int)v[i].size());
	
	int n; scanf("%d", &n);
	for(int i=0;i<n;i++) printf("%d%c", v[2][i], i<n-1 ? ' ' : '\n');
	
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define llinf 1e17
#define nllinf -4e18
 
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll,ll> 
#define vpll vector<pair<ll,ll > >
 
#define repup(a,b,i) for(i=a;i<=b;i++)
#define repdown(a,b,i) for(i=b; i>=a; i--)
#define repupx(a,b,i,x) for(i=a;i<=b;i+=x)
	
#define repit(v,it) for(it=v.begin(); it!=v.end(); it++)
#define itall(v) v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first
#define sc second
 
#define err(n) cout<<n<<" ";
#define t1 cout<<",";
 
ll MOD= 998244353;


int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll i,j,k;

ll n,m;cin>>n>>m;
vll g[n+1];
ll indegree[n+4]={0};
ll ans[n+2]={-1};
repup(0,m-1,i){
	ll a,b;cin>>a>>b;
	g[a].pb(b);
	indegree[b]++;
}
repup(1,n,i){g[0].pb(i);indegree[i]++;}
stack <ll>dfs;
dfs.push(0);ans[0]=0;
while(dfs.size()){
	ll prev= dfs.top();
	dfs.pop();
	for(j=0; j<g[prev].size();j++){
		
		indegree[g[prev][j]]--;
		ans[g[prev][j]] = max(ans[g[prev][j]], ans[prev]+1);
		if(indegree[g[prev][j]]==0){dfs.push(g[prev][j]);}
	}
}
ll temp=-1;
repup(1,n,i){
	temp=max(temp, ans[i]);
}
err(temp-1)



}

Measured memory_bytes: 8440
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(a*b,c)<<endl;
}


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

int main()
{
  int n,sum=0;
  char Step[1000][2];

  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>Step[i];
    }

    for(int i=0;i<n-1;i++){
      if(Step[i][0] !=Step[i+1][0] &&Step[i][1] ==Step[i+1][1])sum++;
    }
    cout <<sum<< endl;
    sum=0;
  }
  
  return 0;
}

Measured memory_bytes: 1164
from math import factorial

n, m = map(int, input().split())
if abs(n-m) > 1:
    print(0)
    exit()
if n == m:
    print(2 * factorial(n) * factorial(m) % (10**9+7))
else:
    print(factorial(n) * factorial(m) % (10**9+7))


Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define mp make_pair
#define P pair
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))
#define modp(x, y) (((y) + (x) % (y)) % (y))
#define divd(x, y) (static_cast<double>(x) / static_cast<double>(y))

template <ll MOD>
class ModLL {
private:
    ll d_;

private:
    void normalize() { d_ = (MOD + d_ % MOD) % MOD; }

public:
    ModLL() {}
    ModLL(ll d) : d_(d % MOD) {}

    ll get() const { return d_; }

    operator ll() { return d_; }

    ModLL& operator=(const ModLL& rhs)
    {
        d_ = rhs.d_;
        normalize();
    }

    ModLL& operator+=(const ModLL& rhs)
    {
        d_ += rhs.d_;
        normalize();
        return *this;
    }

    ModLL& operator-=(const ModLL& rhs)
    {
        d_ -= rhs.d_;
        normalize();
        return *this;
    }

    ModLL& operator*=(const ModLL& rhs)
    {
        d_ *= rhs.d_;
        normalize();
        return *this;
    }
    ModLL& operator/=(const ModLL& rhs)
    {
        d_ /= rhs.d_;
        normalize();
        return *this;
    }
};

template <ll MOD>
ostream& operator<<(ostream& os, const ModLL<MOD>& rhs)
{
    os << rhs.get();
    return os;
}

using LL = ModLL<1'000'000'007>;

ll n, a[200000], b[200000];
LL s[200000];

LL poww(LL a, LL b)
{
    if (b == 0) return 1;
    if (b == 1) return a;
    if (b % 2 == 0) {
        auto r = poww(a, b / 2);
        r *= r;
        return r;
    }
    auto r = poww(a, b / 2);
    r *= r;
    r *= a;
    return r;
}

int main()
{
    //
    cbuf(b, -1);
    cin >> n;
    rep(i, 0, n + 1) { cin >> a[i]; }
    ll d1, d2, d3;
    rep(i, 0, n + 1)
    {
        if (b[a[i]] != -1) {
            d1 = b[a[i]];
            d3 = n - i;
            d2 = n - d1 - d3 - 1;
            break;
        }
        b[a[i]] = i;
    }

    LL f(1), l(1);

    rep(k, 1, n + 2)
    {
        f *= n - k + 2;
        f *= poww(k, 1000000005);
        auto t = f;
        if (k == 1) {
            t -= 1;
        }
        else if (k - 1 <= d1 + d3) {
            l *= d1 + d3 - k + 2;
            l *= poww(k - 1, 1000000005);
            t -= l;
        }
        cout << t << endl;
    }
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    string s;
    cin >> n >> s;
    vector<set<ll>> vs(26);
    for(i = 0;i < n;++i){
        char tmp = s.at(i);
        vs.at(tmp - 'a').insert(i);
    }
    /**
    vector<char> ss(n);
    for(i = 0;i < n;++i){
        ss.at(i) = s.at(i);
    }**/
    ll q;
    cin >> q;
    for(i = 0;i < q;++i){
        ll com;
        cin >> com;
        if(com == 1){
            ll ind;
            char c;
            cin >> ind >> c;
            --ind;
            char tmp = s.at(ind);
            s.at(ind) = c;
            vs.at(tmp - 'a').erase(ind);
            vs.at(c - 'a').insert(ind);
        }else{
            ll l,r;
            cin >> l >> r;
            ll ans = 0;
            rep(j,26){
                auto it1 = vs.at(j).lower_bound(l-1);
                auto it2 = vs.at(j).lower_bound(r);
                if(it1 != it2) ++ans;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24196
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,P=998244353;

int n,q,v[N<<2],f[N<<2],tag[N<<2],a[N];
void pushup(int o){
	f[o]=(f[o<<1]+f[o<<1|1])%P;
}
void build(int l,int r,int o){
	tag[o]=0;
	if(l==r){
		v[o]=a[l];
		f[o]=v[o];
		return;
	}
	int mid=l+r>>1;
	build(l,mid,o<<1);
	build(mid+1,r,o<<1|1);
	v[o]=(v[o<<1]+v[o<<1|1])%P;
	f[o]=v[o];
}
void pushdown(int o){
	tag[o<<1]=tag[o];
	tag[o<<1|1]=tag[o];
	f[o<<1]=(1LL*v[o<<1]*tag[o])%P;
	f[o<<1|1]=(1LL*v[o<<1|1]*tag[o])%P;
	tag[o]=0;
	return;
}
void modify(int l,int r,int o,int ld,int rd,int d){
	if(l>=ld&&r<=rd){
		f[o]=(1LL*v[o]*d)%P;
		tag[o]=d;
		return;
	}
	if(tag[o])pushdown(o);
	int mid=l+r>>1;
	if(ld<=mid)modify(l,mid,o<<1,ld,rd,d);
	if(rd>mid) modify(mid+1,r,o<<1|1,ld,rd,d);
	pushup(o);
}
int main(){
	scanf("%d%d",&n,&q);
	a[n]=1;
	for(int i=n-1;i;i--)a[i]=(1LL*a[i+1]*10)%P;
	build(1,n,1);
	while(q--){
		int l,r,d;
		scanf("%d%d%d",&l,&r,&d);
		modify(1,n,1,l,r,d);
		printf("%d\n",f[1]);
	}
}

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


using namespace std;

int main()
{
    ll cnt = 0;
    string s, t;
    cin>>s>>t;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != t[i]){
            cnt++;
        }
    }
    cout<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 3920
//
// Created by chuta on 2020/09/19.
//

#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main() {
    //CFS;
    int n, k;
    cin >> n >> k;
    vi l(k), r(k);
    vl rui(n + 1);
    rep(i, k) {
        cin >> l[i] >> r[i];
        r[i]++;
    }
    rui[0] = 1;
    rui[1] = -1;
    ll x = 0;
    rep(i, n - 1) {
        x = (x + rui[i]) % MOD;
        rep(j, k) {
            (rui[min(n, i + l[j])] += x)%=MOD;
            ((rui[min(n, i + r[j])] -= x)+=MOD)%=MOD;
        }
    }
    cout << (x + rui[n - 1])%MOD << endl;
    return 0;
}


Measured memory_bytes: 4828
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int n;
    ll k;
    vector<pair<int,int>> a;
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        int x,y;
        cin >> x >> y;
        a.push_back(make_pair(x,y));
    }
    sort(all(a));
    ll sum = 0;
    int i = 0;
    while(sum < k){
        sum += a[i].second;
        i++;
    }
    cout << a[i-1].first << endl;
    return 0;
}


Measured memory_bytes: 1400
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), mod = 1000000007;
        long ans = 0;
        if(Math.abs(n - m) > 1) ans = 0;
        else{
            long nn = 1, mm = 1;
            for(int i = 1; i <= n; i++)
                nn = nn * i % mod;
            for(int i = 1; i <= m; i++)
                mm = mm * i % mod;
            if(n == m) ans = 2 * nn * mm % mod;
            else ans = nn * mm % mod;
        }
        System.out.print(ans);
    }
}

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

#define ll long long

struct work {
    ll A;
    ll B;
};

int main() {
    ll N;
    cin >> N;
    work wk[N];

    for(int i = 0;i < N;i++) {
        cin >> wk[i].A >> wk[i].B;
    }
    auto cmp = [](work w1, work w2) {return w1.B < w2.B;};
    sort(wk, wk + N, cmp);
    ll t = 0;
    bool nya = true;
    for(int i = 0;i < N;i++) {
        t += wk[i].A;
        nya = nya && t <= wk[i].B;
    }
    if(nya) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const LL INF = 1LL << 60;

int p0[2005], p1[2005];
int hv0[4005][2005], hv1[4005][2005];
LL dp[2005][2005];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	rep(i, n * 2) {
		char tp;
		int x;
		cin >> tp >> x;
		if(tp == 'W') p0[x] = i;
		else p1[x] = i;
	}
	rep(i, n * 2) {
		hv0[i][0] = 0;
		rep1(j, n) hv0[i][j] = hv0[i][j - 1] + (p0[j] > i);
	}
	rep(i, n * 2) {
		hv1[i][0] = 0;
		rep1(j, n) hv1[i][j] = hv1[i][j - 1] + (p1[j] > i);
	}
	dp[0][0] = 0;
	for(int i = 0; i <= n; i ++) for(int j = 0; j <= n; j ++) {
		if(i == 0 && j == 0) continue;
		dp[i][j] = INF;
		if(i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + hv0[p0[i]][i] + hv1[p0[i]][j]);
		if(j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + hv0[p1[j]][i] + hv1[p1[j]][j]);
	}
	cout << dp[n][n] << '\n';
	return 0;
}

Measured memory_bytes: 94336
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include<queue>
#include<stack>

using namespace std;

int a, b, c;

int main(){
  cin >> a >> b >> c;
  int m = b/a;
  if(c <= m){
    cout << c << endl;
  }else{
    cout << m << endl;
  }
}

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

int gcd(int n1, int n2){
  if(n1 % n2 == 0) return n2;
  else return gcd(n2, n1 % n2);
}

int main() {
  int n;
  cin >> n;
  std::vector<int> v(n, 0);
  for(int i = 0; i <= n-2; i++){
    int a;
    cin >> a, a--;
    v[a]++;
  }
  rep(i, n) cout << v[i] << endl;
}


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


void solve(){
	llint n;
	cin >> n;
	vector<llint>v(n);
	llint cnt4=0;
	llint cnt2=0;
	for(int i=0;i<n;i++)cin >> v[i];
	for(llint x:v){
		if(x%4==0)cnt4++;
		else if(x%2==0)cnt2++;
	}
	if(n/2<=cnt4+cnt2/2)cout << "Yes";
	else cout << "No";
	cout << endl;


}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;
const ll INF = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2); return sq*sq; } else { return N*RS(N, P - 1); } } //power(repeat-square,fast)
ll nPr(ll n, ll r) { ll ans = 1; rep(i, r) { ans = ans * (n - i); } return ans; } //permutation
ll nCr(ll n, ll r) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1); bunshi = bunshi * (n - i); } return bunshi / bunbo; } //combination
ll RS(ll N, ll P, ll Mod) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination


int main(void) {
  ll N,K; cin >> N >> K;
  ll mul = N/K;
  ll res = abs(N - mul*K);
  if (abs(res - K) < res) res = abs(res - K);
  cout << res << "\n";
  return 0;
}


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

using namespace std;


int main() {
    int n;
    string s;
    cin >> n >> s;
    int r = 0,b = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'R') {
            r++;
        } else {
            b++;
        }
    }
    if(r > b) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

//Define Math
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
  int a,b;
  cin >> a >> b;
  if(a*b%2==0)cout << "Even" << endl; else cout << "Odd" << endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int min, int max) {
  if (min < 2) min = 2;
  vector < int > int_array;
  for (int i = min; i <= max; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(max);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

int MaxCD(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {
  return nPr(n, n);
}

ll nCr(ll n, ll r) {
  if (r == 0) return -1;
  else {
    if (0 != n - r && n - r < r) r = n - r;
    return nPr(n, r) / nE(r);
  }
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace tes
{
    class Program
    {
        static void Main(string[] args)
        {
            // ??´??°?????°
            var n = int.Parse(Console.ReadLine());
            // n????????´??°????????????????????????
            var line2 = Console.ReadLine().Split();
            
            double[] x = new double[n];
            double max, min, sum;

            for (int i = 0; i < n; i++)
            {
                x[i] = double.Parse(line2[i]);
            }

            max = x.Max();
            min = x.Min();
            sum = x.Sum();

            Console.WriteLine("{0} {1} {2}",min,max,sum);
        }
    }
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, K;
    cin >> N >> K;

    vector<ll> h(N);
    rep (i, N) {
        cin >> h[i];
    }

    ll ans = 0;
    rep (i, N) {
        if (h[i] >= K) {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;


/*----------------------------------------------------------------*/
signed main(){

	string s,t;
	cin >> s >> t;
    cout << t << s << endl;



	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc149.contest.atcoder.jp/tasks/abc149_b

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

ll n, a, b;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
ll val = (n / (a + b)) * a;
n %= (a + b);
val += min(n, a);
cout << val << endl;

return 0;
}



Measured memory_bytes: 256
use std::io;
fn main(){
    
    let mut a = String::new();
    io::stdin().read_line(&mut a).unwrap();
    let mut v = a.split_whitespace()
        .map(|x| x.parse::<i32>().unwrap()).collect::<Vec<i32>>();


    v.sort();

    println!("{}",v[0]+v[1] );

}

Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func bisectLeft(a []int, x int) int {
	lo := 0
	hi := len(a)
	for lo < hi {
		mid := (lo + hi) / 2
		if a[mid] < x {
			lo = mid + 1
		} else {
			hi = mid
		}
	}
	return lo
}

func main() {
	N := readInt()
	L := make([]int, N)
	for i := 0; i < N; i++ {
		L[i] = readInt()
	}

	sort.Sort(sort.IntSlice(L))
	result := 0
	for i := 0; i < N-2; i++ {
		for j := i + 1; j < N-1; j++ {
			x := L[i] + L[j]
			result += bisectLeft(L, x) - j - 1
		}
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
double r, pi = 3.1415926, c;
int read()
{
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * w;
}
inline void write(int x)
{
  static int sta[35];
  int top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[-- top] + 48);
}
int main()
{
    r = read();
    c = 2 * r * pi;
    printf("%.3f", c);
    return 0;
}

Measured memory_bytes: 3760
import javax.swing.*;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int[][] arr = new int[count][3];
        int[][] values = new int[count][3];
        for (int i = 0; i < count; i++) {
            for (int j = 0; j < 3; j++) {
                arr[i][j] = sc.nextInt();
                values[i][j] = 0;
            }
        }
        values[0] = arr[0];
        for (int i = 1; i < count; i++) {
            values[i][0] = arr[i][0] + Math.max(values[i - 1][1], values[i - 1][2]);
            values[i][1] = arr[i][1] + Math.max(values[i - 1][0], values[i - 1][2]);
            values[i][2] = arr[i][2] + Math.max(values[i - 1][0], values[i - 1][1]);
        }
        

        
        System.out.println(Math.max(Math.max(values[count - 1][0], values[count - 1][1]),values[count - 1][2]));
    }
}

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

int main(void)
{
	char str[1028];
	int len;
	int i;

	fgets(str, sizeof(str), stdin);
	len = strlen(str) - 1;
	for (i = 0; i < len; i++){
		if (strncmp(&str[i], "apple", 5) == 0){
			strncpy(&str[i], "peach", 5);
		}
		else if (strncmp(&str[i], "peach", 5) == 0){
			strncpy(&str[i], "apple", 5);
		}
	}

	printf("%s", str);

	return (0);
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<string> mapa(n), mapb(m);
    rep(i,n) cin >> mapa[i];
    rep(i,m) cin >> mapb[i];

    for(int i = 0; i < n-m+1; i++){
        for(int j = 0; j < n-m+1; j++){
            int slide = 0;
            while(slide < m && mapa[i+slide].substr(j,m) == mapb[slide])
                slide++;
            if(slide == m){
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 256
<?php
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
list($N,$M)=sscanf(trim(fgets(STDIN)),"%d %d");
$sc = new Scanner();
$cnt=0;
$A = array();
$total = 0;
for($i=0;$i<$N;$i++){
    $A[$i] = $sc->nextInt();
    $total += $A[$i];
}

for($i=0;$i<$N;$i++){
    if($A[$i] >= $total * (1/(4*$M))){
        $cnt++;
    }
}

if($cnt >= $M){
    printf("Yes");
}else{
    print("No");
}
//

Measured memory_bytes: 4856
def checkRGB(a,b,c):
    if a == b or b == c or c == a:
        return 0
    else:
        return 1

N = int(input())
S = input()

if N<4:
    print(0)
    exit()
sum1 = S.count("R")*S.count("G")*S.count("B")
sum2 = 0
for i in range(0,N-2):
    left = S[i]
    for j in range(i+1,(N+i)//2+(N+i)%2):
        center = S[j]
        right = S[2*j-i]
        if checkRGB(left,center,right):
            sum2 += 1
print(sum1-sum2)


Measured memory_bytes: 9212
#include<iostream>
#include<cmath>
#include <vector>
using namespace std;
int main() 
{
  double a = 0;
  double b = 0;
  double x = 0;
  double PI = 3.141592653589793;

  cin >> a >> b >> x;

  double w = x / a / b * 2;

  if (w <= a) {
    double atan = atan2(w, b);

    cout << fixed << 90 - (atan * 180) / PI << endl;
  } else {
    double h = 2 * b - (x / a / a * 2);

    double atan = atan2(a, h);
    cout << fixed << 90 - (atan * 180) / PI << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*  Name: Abu Hurayra
    Handle: HurayraIIT
    Institute: IIT_JU   */

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

typedef long long LL;
typedef string S;
typedef double D;
typedef vector<int> vi;
typedef queue<int> qi;
typedef stack<int> si;

#define pi acos(-1.0)
#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define Fin freopen("input.txt","r",stdin)
#define Fout freopen("output.txt","w",stdout)

int main()
{
	off;
    
    int n,i,j;
    cin >> n;
    int a[n],cost[n];
    for(i=0;i<n;i++)
    {
    	cin >> a[i];
    	cost[i] = 1000000000;
    }
    cost[0]=0;
    
    for(i=1;i<n;i++)
    {
    	if(i==1) cost[i] = abs(a[0]-a[1]);
    	else
    	{
    		cost[i] = min(cost[i-1]+abs(a[i-1]-a[i]) , cost[i-2]+abs(a[i-2]-a[i]));
    	}
    }
    
    cout << cost[n-1] << endl;


	return 0;

}



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

int main() {
    string s; cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.length() - 1; i++) {
        if (s[i] != s[i + 1]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
#
# File    : A.rb
# Author  : Kazune Takahashi
# Created : 11/13/2018, 7:46:41 AM
# Powered by Visual Studio Code
#

a, b = gets.chomp.split(" ").map{|i| i.to_i}
if a * b % 2 == 0
  puts "Even"
else
  puts "Odd"
end

Measured memory_bytes: 1916
using System;

namespace ITP1_4_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');

            double min = Double.PositiveInfinity;
            double max = Double.NegativeInfinity;
            long sum=0;

            for(int i=0; i<n; i++)
            {
                if(min > long.Parse(str[i]))
                    min = long.Parse(str[i]);
            }

            for(int j=0; j<n; j++)
            {
                if(max < long.Parse(str[j]))
                    max = long.Parse(str[j]);
            }

            for(int k=0; k<n; k++)
            {
                sum += long.Parse(str[k]);
            }

            Console.WriteLine("{0} {1} {2}", min, max, sum);
        }
    }
}



Measured memory_bytes: 19956
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>  // std::unique
using namespace std;

/*
D - Multiple of 2019
*/

int main(void) {
	int stairNum;
	int brokenNum;
	cin >> stairNum >> brokenNum;

	vector< bool > isSafeStep;
	isSafeStep.assign(stairNum + 1, true);

	for (int i = 0; i < brokenNum; ++i) {
		int n;
		cin >> n;
		isSafeStep[n] = false;
	}

	int answer = 0;

	vector<int> dp(stairNum + 1, 0);

	dp[0] = 1;

	if (isSafeStep[1]) dp[1] = 1;

	for (int i = 2; i <= stairNum; ++i) {
		if (isSafeStep[i - 1])	dp[i] += dp[i - 1];
		if (isSafeStep[i - 2])	dp[i] += dp[i - 2];
		dp[i] %= 1000000007;
	}


	auto output = dp[stairNum];
	cout << output;
}


Measured memory_bytes: 640
while True:
    n=input()
    if n==0:
        break
    dic={}
    for i in range(n):
        pre,pos=raw_input().split()
        dic[pre]=pos.rstrip()
    n=input()
    s=""
    for i in range(n):
        c=raw_input().rstrip()
        if c in dic:
            s+=dic[c]
        else:
            s+=c
    print s

Measured memory_bytes: 7372