akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        string s = ins();
        int c = 0;
        rep(i, s.size())  {
            if (s[i] == 'o') c++; 
        }
        if (15 -s.size() + c >= 8) cout << "YES" << endl;
        else cout << "NO" << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector<int> rabi(n+1);
	for(int i=1; i<=n; i++){
		cin >> rabi[i];
	}
	int ans=0;
	for(int i=1; i<=n; i++){
		if(i==rabi[rabi[i]])ans++;
	}
	cout << ans/2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
int main (void) {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int> a (n,0);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int ctr = 0;
    for (int i = 0; i < n; i++)
        if (4*a[i]*m >= sum) ctr++;
    if (ctr >= m) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> p;
typedef pair<p,p> P;
typedef pair<P,int> PP;
int c,n,used[10],ww;
 
int x0[10];
int y2[10];
int x1[10];
int y3[10];
PP dd[10];
 
void dfs(vector<int> L){
  for(int i=0;i<(int)L.size();i++){
    if(used[L[i]])continue;
    used[L[i]]=++c;
     int minx=ww;
    for(int j=0;j<n;j++)
      if(y2[dd[j].s]<y3[L[i]]&&y3[L[i]]<y3[dd[j].s]&&minx>x0[dd[j].s])minx=x0[dd[j].s];
 
    vector<int> l;
    for(int j=0;j<n;j++)
      if(!used[dd[j].s]&&y3[dd[j].s]<=y3[L[i]]&&minx>=x1[dd[j].s])
    l.push_back(dd[j].s);
    if(l.size())dfs(l);
  }
}
 
 
 
int main(){
  bool f=0;
  while(cin>>n,n){
    if(f)cout<<endl;
    f=1;
    memset(used,0,sizeof(used));
    ww=c=0;
    for(int i=0,q,w,e,r;i<n;i++){
      cin>>q>>w>>e>>r;
      y2[i]=min(w,r);
      x0[i]=min(e,q);
      y3[i]=max(w,r);
      x1[i]=max(e,q);
      ww=max(ww,x1[i]);
      dd[i]=PP(P(p(x0[i],y2[i]),p(x1[i],y3[i])),i);
    }
    sort(dd,dd+n);
    vector<int> v;
    for(int i=0;i<n;i++)v.push_back(dd[i].s);
    dfs(v);
    for(int i=0;i<n;i++)cout<<used[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3092
program ABC085C;
uses SysUtils;
var
	n,y,i,j,k: integer;
begin
	read(n);
	read(y);
	for i:=0 to n do begin
		for j:=0 to n-i do begin
			k:=n-i-j;
			if i*1000+j*5000+k*10000=y then begin
				writeln(IntToStr(k)+' '+IntToStr(j)+' '+IntToStr(i));
				exit;
			end;
		end;
	end;
	writeln('-1 -1 -1');
end.


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

int cnt[200010];
int main(){
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    cnt[a-1]++;
  }
  sort(cnt, cnt+N);
  
  int ans = 0;
  for(int i = 0; i < N-K; i++){
    ans += cnt[i];
  }
  
  cout << ans << endl;
  
  return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int X =sc.nextInt();
		int T =sc.nextInt();

		if(N/X == 0) {
			System.out.println(T);
		}
		else {
			int i = N/X;
			if(N%X==0) {
				System.out.println(T*i);
			}
			else {
				System.out.println(T*i + T);
			}
		}
	}
}


Measured memory_bytes: 27088
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j;
  int n[24];
  double v[24];
  for(i=0;i<3;i++)
    for(j=0;j<8;j++)
      cin>>n[8*i+j]>>v[8*i+j];
  for(i=0;i<3;i++){
    do{
      h=0;
      for(j=1;j<8;j++){
	if(v[8*i+j-1]>v[8*i+j]){
	  swap(v[8*i+j-1],v[8*i+j]);
	  swap(n[8*i+j-1],n[8*i+j]);
	  h=1;
	}
      }
    }while(h);
  }
  for(i=0;i<3;i++){
    printf("%d %.2lf\n",n[8*i],v[8*i]);
    printf("%d %.2lf\n",n[8*i+1],v[8*i+1]);
    v[8*i]=0.0;
    v[8*i+1]=0.0;
  }
  do{
    h=0;
    for(j=1;j<24;j++){
      if(v[j-1]>v[j]){
	swap(v[j-1],v[j]);
	swap(n[j-1],n[j]);
	h=1;
      }
    }
  }while(h);
  printf("%d %.2lf\n",n[6],v[6]);
  printf("%d %.2lf\n",n[7],v[7]);
  return 0;
}

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

int main(){
  int count = 0;
  int a,b,c,x;
  cin >> a >> b >> c >>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        int sum = 500*i+100*j+50*k;
        if(sum==x){count++;}
      }
    }
  }
  cout << count << endl;

}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if ((a == 7 && b == 5 && c == 5)||(a == 5 && b == 7 && c == 5)||(a == 5 && b == 5 && c == 7)) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <numeric>
#include <vector>
	#include<math.h>
#include <algorithm>
	#include <functional>
	#include <numeric>
	//#include<cmath>
//#include <stdio.h> 
#include <cstdint>
	#include <string>
	//#include <cstdlib>
	//#define pi 3.14159265359
#include <iomanip>
#include <map>
#include <cmath>

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


int main() {
	int a;
	cin >> a;
	if (a % 2 == 0) {
		cout << a / 2;
	}
	else {
		cout << a / 2 + 1;
	}

	return 0;

}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()

const ll mod=1000000007;

int countBits(int in){
  int res=0;
  for(int i=0;i<10;i++){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<ll> a(n);
  bool remain=false;
  ll ans=0;
  for(int i=0;i<n;i++){
    ll val;cin>>val;
    if(val<0){
      remain=!remain;
      val*=(-1);
    }
    a[i]=val;
    ans+=val;
  }
  sort(all(a));
  if(remain){
    ans-=a[0]*2;
  }
  cout<<ans<<endl;
  return 0;
}


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

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

	int n;
	cin >> n;
	
	long long ans = 0, podwojne = 0;
	
	for(int i = 1; i < n; i++)
	{
		for(int j = 1; j <= i; j++) 
		{
			if(j * i < n)
			{
				ans++;
				
				if(j == i)
				{
					podwojne++;
				}
			}
			
			else
			{
				break;
			}
		}
	}
	
	cout << 2 * ans - podwojne << "\n";
	return 0;
}


Measured memory_bytes: 3608
'use strict'

function main(input){
  const lines = input.split('\n');
  const N = parseInt(lines.shift());
  const P = lines.shift().split(' ').map(x => parseFloat(x));

  const dp=[];
  for(var i =0;i<N;i++){
    dp.push(Array(N+2).fill(0.0))
  }

  dp[0][0]=P[0];
  dp[0][1]=1-P[0];

  for(var i =1;i<N;i++){
    for(var j=0;j<=i+1;j++){
      let pre_left = dp[i-1][j-1];
      if(pre_left==undefined){pre_left=0.0;}

      let pre_right = dp[i-1][j];
      if(pre_right==undefined){pre_right=0.0;}

      dp[i][j] = pre_left * (1.0 - P[i]) + pre_right * P[i]
    }
  }

  let result = 0;

  for(var i=0;i<N/2;i++){
    result += dp[N-1][i]
  }

  console.log(result);
}

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


Measured memory_bytes: 151160
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  int n;
  cin>>n;
  nvec(long,a,n);
  sort(all(a));
  bool b = count_lt(a,0)%2!=0;
  FOR(i,n){
    a[i]=abs(a[i]);
  }
  cout<<SUM(a)-min_e(a)*2*b;
}

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

using namespace std;

vector<int> poss[26];
int z[26];
int dp[200010];
int nx[200010];
char an[200010];

int main()
{
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0), cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int al = 0;
    int len = 1;
    for (int i = 0; i < n; i++) {
        dp[i] = n + 1;
        s[i] -= 'a';
        poss[s[i]].push_back(i);
    }
    for (int i = 0; i < 26; i++){
        poss[i].push_back(n);
        z[i] = poss[i].size() - 1;
    }
    dp[n + 1] = 0;
    dp[n] = 1;
    nx[n] = n + 1;
    an[n] = 0;
    for (int i = n - 1; i >= 0; i--){
        for (int j = 0; j < 26; j++){
            while (z[j] > 0 && poss[j][z[j] - 1] >= i) z[j]--;
            int k = poss[j][z[j]] + 1;
            if (dp[i] > dp[k] + 1){
                dp[i] = dp[k] + 1;
                nx[i] = k;
                an[i] = j;
            }
        }
    }
    int i = 0;
    while (i != n + 1){
        cout << (char) (an[i] + 'a');
        i = nx[i];
    }
    return 0;
}




Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200;
int n, dep[maxn + 10];
int a[maxn + 10], acnt, mx[maxn + 10];
int ans = 1e9;
ll ansv;
vector<int> g[maxn + 10];

void dfs(int p, int fa) {
	dep[p] = dep[fa] + 1;
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		if (e != fa) dfs(e, p);
	}
}

bool getpath(int p, int fa, int od) {
	a[++acnt] = p;
	if (p == od) return 1;
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		if (e != fa && getpath(e, p, od)) return 1;
	}
	--acnt; return 0;
}

void dfsdeg(int p, int fa, int dep) {
	int cnt = 0;
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		if (e != fa) {
			dfsdeg(e, p, dep + 1); ++cnt;
		}
	}
	mx[dep] = max(mx[dep], cnt);
}

void solvep(int p) {
	int now = 1; ll tot = 1;
	memset(mx, 0, sizeof mx);
	dfsdeg(p, 0, 0);
	for (int i = 0; mx[i]; ++i) {
		tot *= mx[i]; ++now;
	}
	if (now < ans) {
		ans = now; ansv = tot;
	} else if (now == ans && tot < ansv) ansv = tot;
}

void solvee(int x, int y) {
	int now = 1; ll tot = 2;
	memset(mx, 0, sizeof mx);
	dfsdeg(x, y, 0); dfsdeg(y, x, 0);
	for (int i = 0; mx[i]; ++i) {
		tot *= mx[i]; ++now;
	}
	if (now < ans) {
		ans = now; ansv = tot;
	} else if (now == ans && tot < ansv) ansv = tot;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int l, r; scanf("%d%d", &l, &r);
		g[l].push_back(r); g[r].push_back(l);
	}
	for (int i = 1; i <= n; ++i)
	solvep(i);
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j < (int)g[i].size(); ++j)
			solvee(i, g[i][j]);
	printf("%d %lld", ans, ansv);
}


Measured memory_bytes: 256
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(Int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(Int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1LL<<50);

void solve(long long N, std::vector<long long> A, long long Q, std::vector<long long> B, std::vector<long long> C){
  map<Int, Int> cnt;
  Int s = 0;
  rep(i, N){
    cnt[A[i]]++;
    s += A[i];
  }
  rep(q, Q){
    Int temp = cnt[B[q]];
    if(temp){
      s += ((C[q] - B[q]) * temp);
      cnt[C[q]] += temp;
      cnt[B[q]] = 0;
    }
    cout << s << endl;
  }

}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  long long Q;
  scanf("%lld",&Q);
  std::vector<long long> B(Q);
  std::vector<long long> C(Q);
  for(int i = 0 ; i < Q ; i++){
    scanf("%lld",&B[i]);
    scanf("%lld",&C[i]);
  }
  solve(N, std::move(A), Q, std::move(B), std::move(C));
  return 0;
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  int N;
  cin>>N;

  N=N%28;


  if(N%4==0||N%7==0||N==11||N==15||N==19||N==23||N==27||N==18||N==22||N==26){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
<?php

    list($k, $n) = in_ints();
    $a = in_ints();

    $max_shortening = 0;
    for ($i = 0; $i < count($a); $i++) {
        if ($i == 0) {
            $distance = $k - $a[count($a) - 1] + $a[0];
        } else {
            $distance = $a[$i] - $a[$i - 1];
        }
        if ($distance > $max_shortening) {
            $max_shortening = $distance;
        }
    }

    out($k - $max_shortening);

    
    /**
    * お手伝い関数さんたち
    */
    function in() {
        return trim(fgets(STDIN));
    }
    function in_int() {
        return (int)in();
    }
    function in_vals() {
        return explode(' ', in());
    }
    function in_ints() {
        return array_map('intval', in_vals());
    }
    function out($s) {
        echo $s . PHP_EOL;
    }
    function yes() {
        out('Yes');
    }
    function no() {
        out('No');
    }


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

int main()
{
  double n;
  double ans;
  cin >> n;
  int intn;
  intn=n;

  if(intn%2==0){
    cout << "0.5";
  }else{
    ans=(n+1)/2/n;
    cout << ans;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,N) for(int i = 0; i < N; i++)

int H, W;
int L[2010][2010], R[2010][2010], U[2010][2010], D[2010][2010];
vector<string> S;

int main() {
    scanf("%d %d", &H, &W);
    S.resize(H);
    
    for (int i = 0; i < H; i++) cin >> S[i];

    rep(i,H)rep(j,W){
        //L
        if (S[i][j] == '#') L[i][j] = 0;
        else if (j == 0) L[i][j] = 1;
        else L[i][j] = L[i][j-1] + 1;

        //U
        if (S[i][j] == '#') U[i][j] = 0;
        else if (i == 0) U[i][j] = 1;
        else U[i][j] = U[i-1][j] + 1;

        int tempi = H - i - 1;
        int tempj = W - j - 1;

        //R
        if (S[tempi][tempj] == '#') R[tempi][tempj] = 0;
        else if (tempj == W-1) R[tempi][tempj] = 1;
        else R[tempi][tempj] = R[tempi][tempj + 1] + 1;

        //D
        if (S[tempi][tempj] == '#') D[tempi][tempj] = 0;
        else if (tempi == H-1) D[tempi][tempj] = 1;
        else D[tempi][tempj] = D[tempi + 1][tempj] + 1;
        
    }

    int maxsum = 0;
    rep(i,H)rep(j,W) maxsum = max(maxsum, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);

    cout << maxsum << endl;
    return 0;
}

Measured memory_bytes: 67456
module Main where

import Control.Monad
import Control.Applicative
import Data.List

showingList :: [Int] -> String
showingList (x:[]) = show x
showingList (x:xs) = (show x) ++ " " ++ (showingList xs)


main :: IO ()
main = do
    x <- readLn
    print $ x + x * x + x * x * x


Measured memory_bytes: 3940
import sys
import math
import itertools
def input(): return sys.stdin.readline().rstrip()

def main():
    s = list(input())
    g = itertools.groupby(s)
    ans = []
    for key, group in g:
        if key == 'R':
            r = len(tuple(group))
            continue
        l = len(tuple(group))

        ans += [0] * (r-1) + [math.ceil(r/2) + math.floor(l/2)]
        ans += [math.floor(r/2) + math.ceil(l/2)] + [0] * (l-1)
    print(*ans)

if __name__ == '__main__':
    main()

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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
const double PI=3.1415926535897932;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll a,b;

int main(){
    cin >> a >> b;
    if(a <= 8 && b <= 8){
        cout << "Yay!\n";
    }
    else{
        cout << ":(\n";
    }
}

Measured memory_bytes: 256
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#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)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

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

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    std::ifstream in(".txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if ((e-a) > k) {
        cout <<  ":(";
    }
    else {
        cout << "Yay!";
    }



    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int operations = 2;

int main(){

    cin >> N;
    vector<int> p;
    int input;
    for(int i=0;i<N;i++){
        cin >> input;
        p.push_back(input);

        if(input != (i+1)){
            operations--;
        }
    }


    if(operations >= 0){
        cout << "YES";
    }else{
        cout << "NO";
    }



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  if (S.at(K - 1) == 'A') {
    S.at(K - 1) = 'a';
  }
  else if (S.at(K - 1) == 'B') {
    S.at(K - 1) = 'b';
  }
  else {
    S.at(K - 1) = 'c';
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,pm[10001],pe[10001],pj[10001],i,x[10001],y[10001];
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d %d %d",&pm[i],&pe[i],&pj[i]);
			x[i]=(pm[i]+pe[i])/2;
			y[i]=(pm[i]+pe[i]+pj[i])/3;
		}
		for(i=0;i<n;i++){
			if(pm[i]==100||pe[i]==100||pj[i]==100) printf("A\n");
			else if(x[i]>=90||y[i]>=80) printf("A\n");
			else if(y[i]>=70||y[i]>=50&&pm[i]>=80||pe[i]>=80) printf("B\n");
			else printf("C\n");
		}
	}
	return 0;
}	

Measured memory_bytes: 2568
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
    ll x;
    cin>>x;
    ll yol = (x/500);
    ll ans = yol*1000;
    x-=yol*500;
    ans+=(x/5)*5;
    cout<<ans;
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	LL N,x;
	cin >> N >> x;
	LL a[100000];
	for(int i=0; i<N; i++) cin >> a[i];
	LL ans = 0;
	for(int i=1; i<N; i++){
		if(a[i-1]+a[i] > x){
			if(a[i-1] > x){
				ans += a[i];
				a[i] = 0;
				ans += a[i-1]-x;
				a[i-1] = x;
			}
			else{
				ans += a[i] - (x-a[i-1]);
				a[i] = x-a[i-1];
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
from itertools import combinations
INFTY = 10**4
epsilon = 1e-10
def dist(x,y):
    return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5
def cross(x,y):
    return x[0]*y[1]-x[1]*y[0]
def dot(x,y):
    return x[0]*y[0]+x[1]*y[1]
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
rmin = INFTY
for z in combinations(range(N),3):
    i,j,k = z
    x0,y0 = X[i]
    x1,y1 = X[j]
    x2,y2 = X[k]
    r = max(dist(X[i],X[j]),dist(X[j],X[k]),dist(X[k],X[i]))/2
    if r==dist(X[i],X[j])/2:
        x = (x0+x1)/2
        y = (y0+y1)/2
    elif r==dist(X[j],X[k])/2:
        x = (x1+x2)/2
        y = (y1+y2)/2
    else:
        x = (x2+x0)/2
        y = (y2+y0)/2
    a = cross([x1-x0,y1-y0],[x2-x0,y2-y0])
    if a==0:continue
    if dot([x1-x0,y1-y0],[x2-x0,y2-y0])>=0 and dot([x0-x1,y0-y1],[x2-x1,y2-y1])>=0 and dot([x1-x2,y1-y2],[x0-x2,y0-y2])>=0:
        s = ((x1-x0)**2+(y1-y0)**2-(x0+x1-2*x2)**2-(y0+y1-2*y2)**2)/8
        s = s/(x0*y1-x1*y0-x2*y1+x2*y0-x0*y2+x1*y2)
        x = (x0+x1)/2+s*(y1-y0)
        y = (y0+y1)/2+s*(x0-x1)
        r = dist([x,y],[x0,y0])
    flag = 0
    for i in range(N):
        if dist([x,y],X[i])<=r+epsilon:
            continue
        else:
            flag = 1
            break
    if flag==0:
        rmin = min(rmin,r)
if rmin==INFTY:
    rmin = 0
    for i in range(N-1):
        for j in range(i+1,N):
            rmin = max(rmin,dist(X[i],X[j]))
    print(rmin/2)
else:
    print(rmin)

Measured memory_bytes: 76760
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O2")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 
template <typename T> 

void DEBUG_ARR(vt<T> a)
{
	f(i,0,a.size())cout<<a[i]<<" ";
	cout<<"\n";
}

lli tmod(lli x,lli m){return (x%m+m)%m;}//USE AT YOUR OWN RISK

using cd = complex<long double>;
const long double PI = acos(-1);

void fft(vector<cd> & a, bool invert) {
    lli n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    long double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}
vector<lli> multiply(vector<lli> const& a, vector<lli> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    lli n = 1;
    while (n < a.size() + b.size()) 
        n <<= 1;
    fa.resize(n);
    fb.resize(n);
    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<lli> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

int main() 
{ 
  fastio;
  lli n,m;
  cin>>n>>m;
  v64 a(n);f(i,0,n)cin>>a[i];
  v64 freq(100001,0);f(i,0,n)freq[a[i]]++;
  v64 convolution=multiply(freq,freq);
  lli ans=0;
  reverse(convolution.begin(),convolution.end());
  int pos=0;
  while(pos<convolution.size() && m!=0){
      if(m>=convolution[pos]){
          ans+=(convolution.size()-pos-1)*(convolution[pos]);
          m-=convolution[pos];
          pos++;
      }
      else{
          ans+=(convolution.size()-pos-1)*m;
          m=0;
          pos++;
      }
  }
  cout<<ans<<"\n";
  return 0; 	
}


Measured memory_bytes: 36232
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static  ll INF = 1e9;
using namespace std;

signed main(){
	int n;
	cin>>n;
	set<int>a;
	int type=0;
	rep(i,n){
		int m;
		cin>>m;
		if(m<3200)a.insert(m/400);
		else ++type;
	}
	int ans=a.size();
	if(a.size()==0)ans++;
	cout<<ans<<" "<<a.size()+type<<endl;
	return 0;
}


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef unsigned long long ll;
typedef pair<int, int> pii;

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

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

int main(){
    fcin;
    ll n, m;
    cin >> n >> m;

    vector<ll> a(n);
    for(ll i = 0; i < n; i++) cin >> a[i];

    ll L = a[0]/2;
    for(ll i = 1; i < n; i++) L = lcm(L, a[i]/2);
    
    ll ans = 0;
    for(ll i = 0; i < n; i++) if(__builtin_ctz(L) != __builtin_ctz(a[i]/2)) return cout << 0, 0;

    for(ll i = L; i <= m; i += 2LL*L) ans++;

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



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

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 7654321
#define IINF 87654321987654321LL
#define MAXV 200500

ll mod = 1e9 + 7;
int N,M,T,K,tc;
int p[100][100];
int main(){
	repp(i,3) repp(j,3) geti(p[i][j]);

	set<int> s;
	//1
	for(int i=1;i<=3;i++){
		s.insert( p[2][i] - p[1][i] );
	}
	if( sz(s) > 1 ){
		printf("No\n");
		return 0;
	}

	s.clear();

	//2
	for(int i=1;i<=3;i++){
		s.insert( p[3][i] - p[2][i] );
	}
	if( sz(s) > 1 ){
		printf("No\n");
		return 0;
	}

	s.clear();

	//3 
	for(int i=1;i<=3;i++){
		s.insert( p[i][2] - p[i][1] );
	}
	if( sz(s) > 1 ){
		printf("No\n");
		return 0;
	}
	s.clear();	
	//4
	for(int i=1;i<=3;i++){
		s.insert( p[i][3] - p[i][2] );
	}
	if( sz(s) > 1 ){
		printf("No\n");
		return 0;
	}

	s.clear();


	printf("Yes\n");
}


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

//mod逆元を使ったnCkの計算(速)
const int64_t MAX = 510000;
const int64_t MOD = 1000000007;

int64_t fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
int64_t COM(int64_t n, int64_t k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int64_t N, M, K;
  cin >> N >> M >> K;
  int64_t ans = 0;
  
  int64_t n = N*(N*N-1) / 6;
  n %= MOD;
  n *= M*M;
  n %= MOD;
  
  int64_t m = M*(M*M-1) / 6;
  m %= MOD;
  m *= N*N;
  m %= MOD;
  
  ans = n + m;
  ans %= MOD;

  
  COMinit();
  int64_t all = COM(N*M-2,K-2);
  
  ans *= all;
  ans %= MOD;
  
  cout << ans << endl;
  
}

Measured memory_bytes: 12160
n = int(input())
list_W = [input() for _ in range(n)]
list_S = [list_W[0]]
ans = "Yes"
for i in range(1, n):
    a = list(list_W[i-1])
    b = list(list_W[i])
    if a[-1] != b[0] or list_W[i]  in list_S:
        ans = "No"
    list_S.append(list_W[i])

print(ans)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(b/a,c)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
        string s;
        cin>>s;
        int a=0;
        for(int i=0;i<s.size();i++){
            a+=(s[i]-48);
        }
        if(a%9==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
   
}


Measured memory_bytes: 3752
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t n, a, b;
  cin >> n >> a >> b;
  int64_t ans = n / (a + b) * a;
  ans += min(n % (a + b), a);
  cout << ans << endl;
  return 0;
}
//templete by private_yusuke


Measured memory_bytes: 888
s = input()
q = int(input())
t = 0
f = -1
x = ["",""]
for i in range(q):
    que = input().split()
    if que[0] == "1":
        t += 1
    else:
        x[(int(que[1])-1+t)%2] += que[2]

s = x[0][::-1] + s + x[1]
if t%2 == 1:
    s = s[::-1]

print(s)


Measured memory_bytes: 4456
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return 1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////

int main() {

string s;
cin>>s;
int n=s.size();

int a[n+1];
int cnt=0;
int dis=0;
for(int i=0;i<=n-1;i++){
a[i]=-1;
}
for(int i=0;i<=n-1;i++){
if(s[i]=='R'){cnt=i;
dis=0;
}
if(s[i]=='L'){
	if(dis%2==1){a[i]=cnt+1;}
	else{a[i]=cnt;}
}
dis++;

}
cnt=0;
dis=0;

for(int i=n-1;i>=0;i--){
if(s[i]=='L'){cnt=i;
dis=0;
}
if(s[i]=='R'){
	if(dis%2==1){a[i]=cnt-1;}
	else{a[i]=cnt;}
}
dis++;

}

int ans[n+1];

for(int i=0;i<=n-1;i++){
	ans[i]=0;
}
for(int i=0;i<=n-1;i++){
	ans[a[i]]++;
}

rrep(i,n){
	if(i<=n-2){
	cout<<ans[i]<<" ";
	continue;}
	cout<<ans[i]<<endl;

}

return 0;
}




Measured memory_bytes: 1408
#include<stdio.h>

#define MAX 100000

int binarySearch(int);

int arr1[MAX];
int n1;

int main(){
  
  int i,n2,ans=0,key;

  
  scanf("%d",&n1);
  for(i=0;i<n1;i++){
    scanf("%d",&arr1[i]);
  }
  
  scanf("%d",&n2);
  for(i=0;i<n2;i++){
    scanf("%d",&key);
    if(binarySearch(key)==1){
      ans++;
    }
  }
  
  printf("%d\n",ans);


  return 0;
}
 

int binarySearch(int key){

  int left,right,mid;
  
  left = 0;
  right = n1;
  
  while(left<right){
    mid=(left + right)/2;
    if(arr1[mid]==key){
      return 1;
    }
    else if(key<arr1[mid]){
      right = mid;
    }
    else left = mid +1;
  }
  
  return 0;
  
}

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

#define    ll    long long int

int main( )
{
    int a, b;
    cin >> a >> b;
    if (a >= 1 && a <= 9 && b >= 1 && b <= 9)
        cout << a * b << "\n";
    else
        cout << "-1\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//全体の長さを入力
		int n = sc.nextInt();
		//料金所の数を設定
		int m = sc.nextInt();
		//初期位置を設定
		int x = sc.nextInt();
		//料金・通過のカウント
		int move = 0;
		int fee = 0;
		//料金所の位置と料金設定
		int a[] = new int[n+1];
		for(int i = 0;i < m;i++) {
			move = sc.nextInt();
			a[move] = 1;
		}
		//前後別の試行
		for(int i = x;i < n;i++) {
			fee = fee + a[i];
		}
		//一時置き換え
		move = fee;
		fee = 0;
		for(int i = x;i > 0;i--) {
			fee = fee + a[i];
		}
		//どちらが少ないかを判定
		if(move > fee) {
			move = fee;
		}
		//出力
		System.out.println(move);
		sc.close();
	}
}

Measured memory_bytes: 22868
N = int((input()))
S = input().split()
s=[]
b=[]
#print(S)
for i in range (N):
  s.append(int(S[i]))
#print(s)
for i in range(N):
  if s[i]==i+1:
    pass
  else:
    b.append(i)
#print(b)
if len(b)<3:
  print("YES")
else:
  print("NO")

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

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

    int n;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    int now = A[0], cnt = 0, ans = 0;
    for(int i = 1; i < n; i++){
        if(now >= A[i]){
            cnt++;
        }else{
            ans = max(ans, cnt);
            cnt = 0;
        }
        now = A[i];
    }

    cout << max(ans, cnt) << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner

import scala.math.Ordering

object Main {

  case class Spell(tile: Char, dir: Int)

  def read(): (Int, Int, String, IndexedSeq[Spell]) = {
    val sc = new Scanner(System.in)
    val n, q = sc.nextInt()
    val s = sc.next()
    val spells = for (_ <- 0 until q) yield {
      val t = sc.next()(0)
      val dir = sc.next()(0)
      val dirI = if (dir == 'L') -1 else 1
      Spell(t, dirI)
    }
    (n, q, s, spells)
  }


  def solve(n: Int, q: Int, tiles: String, spells: IndexedSeq[Spell]): Int = {
    sealed trait GolemResult
    case object VanishLeft extends GolemResult
    case object VanishRight extends GolemResult
    case class Alive(tileIdx: Int) extends GolemResult // i: いるマスのindex

    def castSpells(golemIdx: Int): GolemResult = {
      var currentGolemIdx = golemIdx
      for (spell <- spells) {
        if (spell.tile == tiles(currentGolemIdx)) {
          currentGolemIdx += spell.dir
          if (currentGolemIdx < 0) {
            return VanishLeft
          } else if (currentGolemIdx >= n) {
            return VanishRight
          }
        }
      }
      Alive(currentGolemIdx)
    }

    // 配列外対応になるように拡張
    def castSpellsExp(golemIdx: Int): GolemResult = {
      if (golemIdx < 0) VanishLeft
      else if (golemIdx >= n) VanishRight
      else castSpells(golemIdx)
    }

    // (0 until n).map(castSpells): VL, VL, VL, VL, A, A, A, VR, VR, VR
    // のような構造

    // i: castSpellsExp(i-1) == VanishLeft && castSpellsExp(i) != VanishLeft
    // [0, n]
    val vanishLeftRangeEnd = {

      // [begin, end)の範囲に答えがある
      def sub(begin: Int, end: Int): Int = {
        val mid = (begin + end) / 2
        if (castSpellsExp(mid - 1) == VanishLeft && castSpellsExp(mid) != VanishLeft) {
          mid
        } else if (castSpellsExp(mid - 1) == VanishLeft && castSpellsExp(mid) == VanishLeft) {
          sub(mid, end)
        } else {
          sub(begin, mid)
        }
      }

      sub(0, n + 1)
    }

    // i: castSpellsExp(i-1) != VanishRight && castSpellsExp(i) == VanishRight
    val vanishRightRangeBegin = {
      // [begin, end)の範囲に答えがある
      def sub(begin: Int, end: Int): Int = {
        val mid = (begin + end) / 2
        if (castSpellsExp(mid - 1) != VanishRight && castSpellsExp(mid) == VanishRight) {
          mid
        } else if (castSpellsExp(mid - 1) == VanishRight && castSpellsExp(mid) == VanishRight) {
          sub(begin, mid)
        } else {
          sub(mid, end)
        }
      }

      sub(0, n + 1)
    }
    // aliveの範囲: [vanishLeftRangeEnd, vanishRightRangeBegin)
    vanishRightRangeBegin - vanishLeftRangeEnd
  }

  def main(args: Array[String]): Unit = {
    val (n, q, s, spells) = read()
    println(solve(n, q, s, spells))
  }
}

Measured memory_bytes: 77400
#include <cstdio>
int main(){
	int a,b,c;
	int r1=0, r2=0;
	while(scanf("%d,%d,%d", &a, &b, &c)!=EOF){
		if(a*a+b*b==c*c)
			r1++;
		else if(a==b)
			r2++;
	}
	printf("%d\n%d\n", r1, r2);
	return 0;
}


Measured memory_bytes: 2684
#include<iostream>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#include <vector>
#include<cstdio>
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    vector<int> vc(n);
    for(int i=0;i<n;i++)scanf("%d",&vc[i]);
    int ans=0,q,a;
    scanf("%d",&q);
    sort(vc.begin(),vc.end());
    while(q--){
        cin>>a;
        if(binary_search(vc.begin(),vc.end(),a))ans++;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 3272
#include <stdio.h>
#include <vector>
#include <iostream>

static int cnt = 0;

void insertionSort(std::vector<int> &A, int n, int g)
{
    for (int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(std::vector<int> &A, int n)
{
    cnt = 0;
    int m = 0;
    std::vector<int> G(0);

    int n2 = n;
    if (n2 <= 1)
    {
        m = 1;
        G.push_back(1);
    } else {
        while (n2 > 1) {
            n2 /= 2;
            G.push_back(n2);
            m++;
        }
    }
    std::cout << m << "\n";
    std::cout << G[0];
    for (int i = 1; i < m; i++) {
        std::cout << " " << G[i];
    }
    std::cout << "\n";

    for (int i = 0; i < m; i++) {
        insertionSort(A, n, G[i]);
    }
    std::cout << cnt << "\n";
}

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

    std::vector<int> A(n);
    for (int i = 0; i < n; i++) {
        std::cin >> A[i];
    }

    shellSort(A, n);
    for (int i = 0; i < n; i++) {
        std::cout << A[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 6672
def main():
    n, m = map(int, input().split())
    g1 = []
    g2 = []
    for _ in range(m):
        x, y = map(int, input().split())
        if x == 1:
            g1.append(y)
        elif y == n:
            g2.append(x)
    sx = set(g1)
    sy = set(g2)
    sxy = sx.intersection(sy)
    if len(sxy):
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

if __name__ == '__main__':
    main()


Measured memory_bytes: 21856