akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair


int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    int n, p;
    scanf("%d%d", &n, &p);
    bool odd = false;
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        odd |= x & 1;
    }
    ll ans = 1LL << (n - 1);
    if (!odd) {
        if (p == 0)
            cout << ans * 2 << endl;
        else
            cout << 0 << endl;
    }
    else
        cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];
int main() {
	ll n;
	cin>>n;

	cout<<(n*(n-1))/2<<endl;	
	return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

template <class RandomIt>
void isort(RandomIt beg, RandomIt end) {
    /* Insertion sort */
    using T=typename RandomIt::value_type;
    for (RandomIt it=beg+1; it<end; ++it) {
        T v=*it;
        RandomIt it2;
        for (it2=beg; it2<end; ++it2)
            printf("%d%c", *it2, it2<end-1? ' ':'\n');

        for (it2=it-1; beg<=it2&&*it2>v; --it2)
            it2[1] = it2[0];

        it2[1] = v;
    }
}

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

    vector<int> A(N);
    for (size_t i=0; i<N; ++i)
        scanf("%d", &A[i]);

    isort(A.begin(), A.end());

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

    return 0;
}

Measured memory_bytes: 2680
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	long long N;
	cin >> N;

	const long long mod = 1E9 + 7;
	long long ret = 1;
	for(long long i=2; i<=N; i++)
	{
		ret *= i;
		ret %= mod;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int l;double a, b, c, d; cin >> l >> a >> b >> c >> d;
	cout << l - (int)max(ceil(a / c), ceil(b / d)) << endl;
	return 0;
}

Measured memory_bytes: 3208
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 50;
int n;
vector<string> S;
vector<map<char, int> > v;


void solve() {
    EACH(m, v[0]) {
        int temp = INF;
        REP(j, n) {
            temp = min(v[j][m.first], temp);
        }
        REP(k, temp) cout << m.first;
    }
}

int main() {
    cin >> n;
    string temp;
    REP(i, n) {
        cin >> temp;
        S.emplace_back(temp);
        map<char, int> mp = {
                {'a', 0},
                {'b', 0},
                {'c', 0},
                {'d', 0},
                {'e', 0},
                {'f', 0},
                {'g', 0},
                {'h', 0},
                {'i', 0},
                {'j', 0},
                {'k', 0},
                {'l', 0},
                {'m', 0},
                {'n', 0},
                {'o', 0},
                {'p', 0},
                {'q', 0},
                {'r', 0},
                {'s', 0},
                {'t', 0},
                {'u', 0},
                {'v', 0},
                {'w', 0},
                {'x', 0},
                {'y', 0},
                {'z', 0}
        };
        REP(j, temp.length()) mp[temp[j]]++;
        v.emplace_back(mp);
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
s = input()

if s[-1] == s[-2]:
    print(len(s)-1, len(s))
    exit()

for i in range(len(s)-2):
    if s[i] == s[i+1]:
        print(i+1, i+2)
        exit()
    if s[i] == s[i+2]:
        print(i+1, i+3)
        exit()

print(-1, -1)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<long long int>
#define vi  vector<int>
#define vpi vector<pair<int,int>>
#define prec fixed<<setprecision(12)
#define set(x) __builtin_popcount(x)
#define ffs(x) __builtin_ffs(x)
#define clz(x) __builtin_clz(x)
#define inf 1000000007
#define linf 1000000000000000007
#define a(v) v.begin(),v.end()
void fast(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
}


int main(){
	fast;
    int n;
    cin >> n;
    vll v(n+1);
    for(int i=0;i<n-1;i++){
        int a;
        cin >> a;
        v[a]++;
    }
    for(int i=1;i<=n;i++)cout << v[i]<<'\n';
}


Measured memory_bytes: 4844
/// {{{ Author: Wang, Yen-Jen
// include
#include <bits/stdc++.h>

// using
using namespace std;

// types
typedef long long ll;
typedef pair<int,int> pii;

// macro
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin() , (x).end()
#define REP(i , n) for(int i = 0; i < int(n); i++)
#define REP1(i , a , b) for(int i = a; i <= int(b); i++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LC o<<1 , l , m
#define RC o<<1|1 , m + 1 , r
#define MS(x , v) memset(x , (v) , sizeof(x))

// input
inline bool SR(int &x) {
  return scanf("%d",&x) == 1;
}

inline bool SR(ll &x) {
  return scanf("%lld",&x) == 1;
}

inline bool SR(double &x) {
  return scanf("%lf",&x) == 1;
}

inline bool SR(char *s) {
  return scanf("%s",s) == 1;
}

inline bool RI() {
  return true;
}

template<typename I , typename... T> inline bool RI(I &x , T&... tail) {
  return SR(x) && RI(tail...);
}

// output
inline void SP(const int x) {
  printf("%d",x);
}

inline void SP(const ll x) {
  printf("%lld",x);
}

inline void SP(const double x) {
  printf("%.16lf",x);
}

inline void SP(const char *s) {
  printf("%s",s);
}

inline void PL() {
  puts("");
}

template<typename I , typename... T> inline void PL(const I x , const T... tail) {
  SP(x);
  if(sizeof...(tail)) putchar(' ');
  PL(tail...);
}

// debug
#define WangYenJen

#ifdef WangYenJen
template<typename I> void _DOING(const char *s , I&& x) {
  cerr << s << " = " << x << endl;
}

template<typename I , typename... T> void _DOING(const char *s , I&& x , T&&... tail) {
  int c = 0;
  while(*s != ',' || c != 0) {
    if(*s == '(' || *s == '[' || *s == '{') c++;
    if(*s == ')' || *s == ']' || *s == '}') c--;
    cerr << *s++;
  }
  cerr << " = " << x << " , ";
  _DOING(s + 1 , tail...);
}

#define DEBUG(...) \
do {\
  fprintf(stderr , "%s: Line %d - ",__PRETTY_FUNCTION__,__LINE__);\
  _DOING(#__VA_ARGS__ , __VA_ARGS__);\
} while(0);

#else
#define DEBUG(...)

#endif

// constant number
const int INF = 0x3f3f3f3f;
const ll INF64 = 0x3f3f3f3f3f3f3f3fll;

// random function
inline int RAND() {
  static int x = 880301;
  return (x = x * 0xdefaced + 1) % 0x7fffffff;
}
/// }}}

const int MAX_N = 100000 + 7;

int cnt[MAX_N];
bool can[MAX_N];

int main() {
  int N, M;
  RI(N, M);
  REP1(i, 1, N) {
    cnt[i] = 1;
    can[i] = i == 1;
  }
  while (M--) {
    int x, y;
    RI(x, y);
    cnt[y]++;
    can[y] |= can[x];
    if (--cnt[x] == 0) can[x] = 0;
  }
  int ans = 0;
  REP1(i, 1, N) ans += can[i];
  PL(ans);
  return 0;
}



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

bool used[101010];
int main(){
  int n,k;
  cin >> n >> k;
  pair<int,int> a[n];
  for(int i=0;i<n;i++){cin >> a[i].second >> a[i].first;}
  sort(a,a+n);
  reverse(a,a+n);
  
  priority_queue<int,vector<int>,greater<int>> que;
  long long cnt=0, sum=0;
  for(int i=0;i<k;i++){
    sum+=a[i].first;
    if(!used[a[i].second]){
      ++cnt;
      used[a[i].second]=true;
    }
    else que.push(a[i].first);
  }
  long long ans=sum+cnt*cnt;
  for(int i=k;i<n;++i){
    if(cnt>=k){break;}
    if(used[a[i].second])continue;
    ++cnt;
    used[a[i].second]=true;
    int mini=que.top(); que.pop();
    sum-=mini;
    sum+=a[i].first;
    ans=max(ans,sum+cnt*cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1536
INF = 10 ** 18
N, M = map(int, input().split())
dp = [[INF for _ in range(1 << N)] for _ in range(M + 1)]
cost = [0] * M
bit = [0] * M
for i in range(M):
    cost[i], b = map(int, input().split())
    c = list(map(int, input().split()))
    d = 0
    for j in range(len(c)):
        d |= 1 << (c[j] - 1)
    bit[i] = d

dp[0][0] = 0
for i in range(M):
    for j in range(1 << N):
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
        to = bit[i] | j
        dp[i + 1][to] = min(dp[i + 1][to], dp[i][j] + cost[i])

ans = dp[M][(1 << N) - 1]
if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 109024
#include <stdio.h>
int main(void)
{
	int s1;
	int s2;
	int s3;
	int i;
	int a;
	
    scanf("%d", &i);
    s3 = i % 10;
  	s2 = (i / 10) % 10;
  	s1= (i / 100) % 10;
  
    a = 0;
	
  	switch(s3){
      case 1:
        a++;
        break;
    }
        
   switch(s2){
     case 1:
       a++;
       break;
   }
       
  switch(s1){
    case 1:
      a++;
      break;
  }
  
  if(a >= 1){
    printf("%d", a);
  }
  
  else {
    printf("0");
  }
  
  return(0);
}
      
      

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

int main()
  
{
  int n;
  cin>>n;
  int r=n%10;
  
  if(r==2|| r==4 || r==5 || r==7 || r==9)
  {
    cout<<"hon"<<endl;
  }
  else if(r==0|| r==1|| r==6 || r==8)
  {
      cout<<"pon"<<endl;
  }
  else
  {
      cout<<"bon"<<endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 3636
n,m=map(int,input().split())
lis1 = [list(map(int,input().split())) for _ in range(n)]
lis2 = [list(map(int,input().split())) for _ in range(m)]

def manhattan(lis1,lis2):
    d=0
    for i in range(len(lis1)):
        d+=abs(lis1[i]-lis2[i])
    return d
  
for i in range(n):
    d=3*10**8
    idx=1
    for j in range(m):
        d_new = manhattan(lis1[i],lis2[j])
        if d_new < d:
            d = d_new
            idx = j+1
    print(idx)

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

const long MAX_N=60000;
bool isPrime[MAX_N];

int main(){
	//素数テーブルの設定
	for(long i=2; i<=MAX_N; ++i)
		isPrime[i]=true;
		
	for(long i=2; i<=MAX_N; ++i){
		if(isPrime[i]){
			for(long j=2; i*j<=MAX_N; ++j) isPrime[i*j]=false;
		}
	}
	
	//実際の問題処理
	long n;
	
	while( scanf("%ld", &n) != EOF ){
		long i=n-1;
		while(1){
			if(isPrime[i]){
				printf("%ld ",i);
				break;
			}
			--i;
		}
		
		i=n+1;
		
		while(1){
			if(isPrime[i]){
				printf("%ld\n",i);
				break;
			}
			++i;
		}	
	} 

	return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int N = 2e6 + 6;
int A[N];
int n;

void solve()
{
	string s1 ,s2;
	cin >> s1 >> s2;

	int cnt = 0;

	loop(i,0,s1.length())
	{
		if(s1[i]!=s2[i])
		{
			cout <<"No";
			return;
		}
	}

	cout << "Yes";	
}
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);

ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	

 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 3640
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        a: usize,
        b: usize,
    }

    let ans = a * b;
    println!("{}", ans);
}


Measured memory_bytes: 2200
// AOJ 2439: Hakone
// 2017.11.26 bal4u@uu

#include <stdio.h>
#include <string.h>

#define M 1000000007
char c[202];
long long dp[202][202];

int main()
{
	int n, m, i, j;
	char buf[5];

	scanf("%d", &n);
	for (m = 0, i = 0; i < n; i++) {
		scanf("%s", buf);
		if (*buf != '-') c[m++] = *buf;
	}
	
	dp[0][0] = 1;
	for (i = 0; i < m; i++) for (j = 0; j <= i; j++) {
		if (c[i] == 'U') {
			dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]    ) % M;
			dp[i+1][j]   = (dp[i+1][j]   + dp[i][j] * j) % M;
		} else {
			dp[i+1][j]   = (dp[i+1][j]   + dp[i][j] * j) % M;
	 if (j) dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]*j*j) % M;
		}
	}
	printf("%lld\n", dp[m][0]);
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;



void solve(){
	int n;
	cin>>n;
	if(n<1200)cout<<"ABC";
	else if(n<2800)cout<<"ARC";
	else cout<<"AGC";

}

int main(){
	Red;
	int t=1;
	// cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int n; cin>>n;
  string s;
  REP(i,n){
    cin>>s;
    bool ok = true;
    REP(i,s.size()-1)if(s[i]==s[i+1])ok = false;
    bool t[2]={};
    REP(i,s.size()){
      if(s[i]=='L')t[(i+0)%2] = true;
      else if(s[i]=='R')t[(i+1)%2] = true;
    }
    if(t[0]&&t[1])ok = false;
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

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

// # DEFINES # //
#define ll long long
#define M (ll)1e9+7
#define EPS 1e-9

using namespace std;

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

    int a, b, c;

    cin >> a >> b >> c;

    int res = b/a;

    if(res > c)
        cout << c << endl;
    else 
        cout << res << endl;


    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::Write;
use std::cmp::min;

// {{{
#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// }}}

const INF: usize = std::usize::MAX;

fn main() {
    input! {
        h: usize,
        n: usize,
        magic: [(usize, usize); n],
    }

    let mut atack = vec![];
    let mut mp = vec![];
    for &(ai, mi) in magic.iter() {
        atack.push(ai);
        mp.push(mi);
    }

    // dp[i][j] = i番目までの魔法で体力をj削るのに必要な最小魔法量
    let mut dp = vec![vec![INF; h + 1]; n];

    // i = 0
    for j in 0..(h + 1) {
        dp[0][j] = ((j + atack[0] - 1) / atack[0]) * mp[0];
    }
    // debugln!("{:?}", dp[0]);

    // i >= 1
    for i in 1..n {
        for j in 0..(h + 1) {
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            if j >= atack[i] {
                dp[i][j] = min(dp[i][j], dp[i][j - atack[i]] + mp[i]);
            } else {
                dp[i][j] = min(dp[i][j], mp[i]);
            }
        }
    }

    println!("{}", dp[n - 1][h]);
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream&
operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream&
operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream&
operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

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

    int N; cin >> N;
    vector<pii> X(N);
    rep(i, N) {
        cin >> X[i].first;
        X[i].second = i + 1;
    }
    sort(all(X));
    
    vector<int> arr(N * N, -1);
    rep(i, N) arr[X[i].first - 1] = X[i].second;    
    
    int itr = 0;
    auto insert = [&] (int x, int dir, int pos) {
        while(arr[itr] >= 0 and 0 <= itr and itr < arr.size()) itr += dir;
        if(dir > 0 and itr > pos) return false;
        if(dir < 0 and itr < pos) return false;
        if(0 <= itr and itr < arr.size()) {            
            arr[itr] = x;
            return true;
        }
        return false;
    };
    auto fail = [] () {
        cout << "No" << endl;
        exit(0);
    };

    for(auto p : X) {
        rep(tmp, p.second - 1) if(not insert(p.second, 1, p.first - 1)) fail();
    }

    reverse(all(X));
    itr = arr.size() - 1;
    
    for(auto p : X) {
        rep(tmp, N - p.second) if(not insert(p.second, -1, p.first - 1)) fail();
    }

    cout << "Yes" << endl;
    rep(i, arr.size()) cout << arr[i] << (i + 1 < arr.size() ? " " : "\n");

    return 0;
}


Measured memory_bytes: 2176
using System;
using System.Linq;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		var n = Console.ReadLine();
		var a = Console.ReadLine().Split().Select(x => int.Parse(x));
		int ans = 0;

		while(a.All(x => x % 2 == 0))
		{
			a = a.Select(x => x/2);
			ans++;
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13396
def main():
    N = int(input())
    A =[]
    B =[]
    for i in range(N):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    A.sort()
    B.sort(reverse = True)
    #print(A,B)
    #１を求めるよ
    ans = 0
    ans += len(A)
    for i in range(len(A)-1):
        ans += A[i+1] - A[i] - 1
    #3を求めるよ
    ans += B[len(A)-1]
    #2を求めるよ
    tmp = A[0]-1
    #if B[0]+tmp > 1000000000:
        #ans += 1000000000 - B[0]
    #else:
    ans += tmp

    return ans

print(main())


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

int main(){
  int n;
  cin >> n;
  vector<double> p(n+1);
  rep(i,n) cin >> p[i+1];
  vector<vector<double>> dp(n+1, vector<double>(n+1));
  dp[0][0] = 1;
  for(int i=1; i<=n; i++){
    for(int j=0; j<=n; j++){
      if(j != 0) dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
      else dp[i][0] = dp[i-1][0]*(1-p[i]);
    }
  }
  double ans = 0;
  for(int j=n/2+1; j<=n; j++) ans += dp[n][j];
  printf("%.10f", ans);
}


Measured memory_bytes: 73820
import java.text.ParseException;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            if (n == 0 && m == 0) {
                break;
            }
            List<Integer> l = IntStream.rangeClosed(1, n).boxed().collect(Collectors.toList());
            while (l.size() > 1) {
                n = (n + m - 1) % l.size();
                l.remove(n);
            }
            System.out.println(l.get(0));
        }
    }
}


Measured memory_bytes: 32044
#include<bits/stdc++.h>
using namespace std;
 
int n, h, a, b[100005], amax, cnt;

int main(){
  scanf("%d%d", &n, &h);
  for(int i = 0; i < n; i++){
    scanf("%d%d", &a, &b[i]);
    if(amax < a) amax = a;
  }
  sort(b,b+n, greater<int>());
  for(int i = 0; h > 0 && i < n && b[i] >= amax; cnt++, h-=b[i], i++);
  
  if(h > 0) cnt += (h-1)/amax + 1;
  printf("%d\n", cnt);
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
string S;
int main() {
	getline(cin, S);
	for (int i = 0; i < S.size() - 4; i++) {
		if (S.substr(i, 5) == "apple") {
			S[i] = 'p'; S[i + 1] = 'e'; S[i + 2] = 'a'; S[i + 3] = 'c'; S[i + 4] = 'h';
		}
		else if (S.substr(i, 5) == "peach") {
			S.substr(i, 5) = "apple";
			S[i] = 'a'; S[i + 1] = 'p'; S[i + 2] = 'p'; S[i + 3] = 'l'; S[i + 4] = 'e';
		}
	}
	cout << S << endl;
}

Measured memory_bytes: 1188
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [-1] * len(S)
r = 0
d = 1
for i,s in enumerate(S[::-1]):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[i] = r

ans = 0
c = Counter(p)
for k,n in c.most_common():
  if n > 1:
    ans += n*(n-1)//2
  else:break
print(ans)

Measured memory_bytes: 16604
n = int(input())
a = list(map(int, input().split()))
ans = 0
i = 0
while i < n:
    temp = 0
    for j in range(i+1, n):
        if a[j] == a[i]:
            temp += 1
        else:
            break
    ans += (temp+1)//2 
    i += (temp + 1)
print(ans)



Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class CR
{
    public static string GetText() { return Console.ReadLine(); }
    public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
    public static long GetLong() { return long.Parse(Console.ReadLine()); }
    public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
}

namespace AtCoder.B
{
    public class Program
    {
        public static long A { get; private set; }
        public static long B { get; private set; }
        public static long M { get; private set; }
        public static List<long> A_Prices { get; private set; }
        public static List<long> B_Prices { get; private set; }
        private static List<Waribiki> Waribikis { get; set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = CR.GetLongs();
            A = inputs[0];
            B = inputs[1];
            M = inputs[2];

            A_Prices = CR.GetLongs();
            B_Prices = CR.GetLongs();

            Waribikis = new List<Waribiki>();
            for (int i = 0; i < M; i++)
            {
                inputs = CR.GetLongs();
                Waribikis.Add(new Waribiki
                {
                    X = inputs[0],
                    Y = inputs[1],
                    C = inputs[2],
                });
            }

            var min = A_Prices.Min() + B_Prices.Min();
            foreach (var waribiki in Waribikis)
            {
                var p = A_Prices[(int)waribiki.X - 1] + B_Prices[(int)waribiki.Y - 1] - waribiki.C;
                min = Math.Min(min, p);
            }

            return min;
        }

        class Waribiki
        {
            public long X { get; set; }
            public long Y { get; set; }
            public long C { get; set; }
        }
    }
}


Measured memory_bytes: 36572
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
char sign[307];
string ans;
int a, b, c;
int A, B;
string print(int n) {
	string s = "";
	for (int j = 0; j < n; j++) {
		s += "|";
	}
	return s;
}

int main()
{
	int a, b; cin >> a >> b;
	if (a > 9 || a < 1 || b > 9 || b < 1) {
		cout << -1 << endl;
	}
	else
		cout << a * b << endl;
	return 0;
}


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

int main() {
  int D;
  cin>>D;
  vector<int> sage(26);
  for(int i=0;i<26;i++){
    cin>>sage.at(i);
  }
  vector<vector<int>> man(D,vector<int>(26));
  for(int i=0;i<D;i++){
    for(int j=0;j<26;j++){
      cin>>man.at(i).at(j);
    }
  }
  vector<int> hini(D);
  vector<vector<int>> rkai(D+1,vector<int>(26,1));
  for(int i=0;i<D;i++){
    int A=0,W=man.at(i).at(0)-2*rkai.at(i).at(0)*sage.at(0);
    for(int j=1;j<26;j++){
      int Y=man.at(i).at(j)-2*rkai.at(i).at(j)*sage.at(j);
      if(Y>W){
        W=Y,A=j;
      }
      rkai.at(i+1).at(j)=rkai.at(i).at(j)+1;
    }
    hini.at(i)=A;
    rkai.at(i).at(A)=0;
    rkai.at(i+1).at(A)=1;
  }
  /*for(int i=0;i<D;i++){
    Z+=man.at(i).at(hini.at(i));
    for(int j=0;j<26;j++){
      Z-=rkai.at(i).at(j)*sage.at(j);
    }
    cout<<Z<<endl;
  }*/
  for(int i=0;i<D;i++){
    cout<<hini.at(i)+1<<endl;
  }
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vb=vector<bool>;

ll sum(ll x){return x*(x+1)/2;}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    int n;string s;cin >> n >> s;
    int half[2] = {0,0};
    int left = 0;
    rep(i,n){
        if(s[i]=='('){
            half[0]++;
            left++;
        }
        else {
            half[1]++;
            if(left>=1){
                half[0]--;
                half[1]--;
                left--;
            }
        }
    }
    string head = string(half[1],'(');
    string tail = string(half[0],')');
    cout << head << s << tail << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int A[N];
  rep (i, N) {
    cin >> A[i];
    if (A[i] % 2 == 0 && A[i] % 3 != 0 && A[i] % 5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;

  return 0;
}

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

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

int N,K;
int dp[1000][1010];

int rec(int k, int prev)
{
  if (k == N) return 1;

  int &ret = dp[k][prev];
  if (~ret) return ret;
  ret = 0;

  REP(i, K)
  {
    if (i == prev) continue;
    ret += rec(k+1, i);
  }
  return ret;
}

int main(void)
{
  cin >> N >> K;
  memset(dp, -1, sizeof(dp));
  cout << rec(0,1001) << endl;
  return 0;
}

Measured memory_bytes: 4224
input = __import__('sys').stdin.readline
MIS = lambda: map(int,input().split())
 
# f(a) = z                 a <= x1
#        a+z-x1      x1 <= a <= x2
#        x2+z-x1     x2 <= a
class Sandgraph:
    def __init__(_, X):
        _.z = _.x1 = 0
        _.x2 = X
    
    def add(_, dt):
        # Go towards the ceiling
        d1 = min(dt, X-(_.x2+_.z-_.x1))
        _.z+= d1
        dt-= d1
        # Reduce the diagonal
        d1 = min(dt, _.x2-_.x1)
        _.z+= d1
        _.x2-= d1
    
    def sub(_, dt):
        # Go towards the floor
        d1 = min(dt, _.z)
        _.z-= d1
        dt-= d1
        # Reduce the diagonal
        d1 = min(dt, _.x2-_.x1)
        _.x1+= d1
    
    def __call__(_, a):
        if a <= _.x1: return _.z
        elif a <= _.x2: return a + _.z - _.x1
        else: return _.x2 + _.z - _.x1
 
X = int(input())
k = int(input())
rev = list(MIS())
Q = int(input())
sand = Sandgraph(X)
 
last_t = 0
i = 0 # even -, odd +
for QUERY in range(Q):
    t, a = MIS()
    while i<k and rev[i] <= t:
        dt = rev[i] - last_t
        if i%2 == 0: sand.sub(dt)
        else: sand.add(dt)
        last_t = rev[i]
        i+= 1
    dt = t - last_t
    if i%2 == 0: sand.sub(dt)
    else: sand.add(dt)
    print(sand(a))
    last_t = t

Measured memory_bytes: 15020
// ABC139 B - Power Socket
// 20190902

using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            // Console.WriteLine("Hello World!");
            //入力受け取り
            string str = Console.ReadLine();
            string[] arr = str.Split(' ');

            int A = int.Parse(arr[0]);
            int B = int.Parse(arr[1]);

            //計算
            int count = 1;
            int C = A;

            while (C < B)
            {
                C += A - 1;
                count++;
            }

            if(B == 1)
            {
                count = 0;
            }
            
            //出力
            Console.WriteLine(count);

        }
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

struct union_find {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    union_find(int n) : par(n), rank(n), siz(n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    void init(int n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
            siz[y] += siz[x];
        } else {
            par[y] = x;
            siz[x] += siz[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return siz[root(x)];
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        p[i]--;
    }
    union_find u(n);
    int x, y;
    for (int i = 0; i < m; ++i) {
        cin >> x >> y;
        x--; y--;
        u.unite(x, y);
    }

    int res = 0;
    for (int i = 0; i < n; ++i) {
        if(u.same(i, p[i]) ) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s, t;
  cin >> s >> t;
  int n = s.size();
  REP(i, n){
    bool ok = true;
    REP(j, n){
      if(s[(i+j)%n] != t[j]) ok = false;
    }
    if(ok){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <map>
using namespace std;
using ll = long long;
const ll INF = 1<<30;
const ll MOD = (ll)1e9 + 7;
const ll MAX_N = (ll)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(ll i = 0; i < (ll) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    ll n; cin >> n;


    map<pair<char, char>, ll> mp;

    for(ll i = 1; i <= n; i++)
    {
        string s = to_string(i);
        mp[make_pair(s.front(), s.back())]++;
    }

    ll ans = 0;
    for(ll i = 1; i <= n; i++)
    {
        string s = to_string(i);
        ans += mp[make_pair(s.back(), s.front())];
    }
    cout << ans << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0
for i in range(min(N,K)+1):
  for j in range(min(N,K)-i+1):
    if j == 0:
      Selected = V[:i]
    else:
      Selected = V[:i] + V[-j:]
    count = K - i - j
    #print(i,j,Selected,count)
    Selected.sort()
    for k in range(min(len(Selected),count)):
      if Selected[k] < 0:
        Selected[k] = 0
    ans = max(ans,sum(Selected))
print(ans)


Measured memory_bytes: 40816
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

struct Weighted_Graph {
  struct edge { ll node, cost; };
  vector<vector<edge>> e;

  void set(ll x) {
	e.resize(x + 1);
  }

  void add_edge(ll a, ll b, ll c) { e[a].pb(edge{ b,c }); }

  vll dijkstra(ll start) {
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	ll u;
	pll p;
	vll dist(e.size(), inf);
	dist[start] = 0;
	pq.push(pll(0, start));

	while (!pq.empty()) {
	  p = pq.top(); pq.pop();
	  u = p.second;
	  if (dist[u] < p.first) continue;
	  for (edge e1 : e[u]) {
		if (dist[e1.node] > dist[u] + e1.cost) {
		  dist[e1.node] = dist[u] + e1.cost;
		  pq.push(pll(dist[e1.node], e1.node));
		}
	  }
	}
	return dist;
  }

};


int main(void) {
  cin >> n;
  Weighted_Graph wg;
  vll d;
  ll a, b, c, q, k;
  wg.set(n);
  rep(i, n - 1) {
	scan(a); scan(b); scan(c);
	wg.add_edge(a, b, c);
	wg.add_edge(b, a, c);
  }
  cin >> q >> k;
  d = wg.dijkstra(k);

  rep(i, q) {
	scan(a); scan(b);
	cout << d[a] + d[b] << endl;
  }

  return 0;
}

Measured memory_bytes: 11120
#include <iostream>

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] input = line.split("");

        boolean flag = false;

        for(int i=0;i<input.length;i++){
            for(int j=i+1;j<input.length;j++){
                if(input[i].equals(input[j])){
                    flag=true;
                    break;
                }
            }
        }
        if(flag){
            System.out.println("no");
        }else{
            System.out.println("yes");
        }

    }
}


Measured memory_bytes: 21332
#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 main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m; cin >> n >> m;

  cout << ((n*(n-1)/2) + (m*(m-1)/2)) << endl;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int main() {
  std::cout << std::fixed << std::setprecision(20);

  int64_t N;
  cin >> N;
  vector<vector<int64_t>> A(N,vector<int64_t>(2));
  REP(i,N){
    A[i][0] = i;
    cin >> A[i][1];
  }

  sort(ALL(A),[](const vector<int64_t> &a, const vector<int64_t> &b){return a[1] < b[1];});

  REP(i,N){
    cout << A[i][0]+1;
    if(i < N - 1) cout << " ";
  }
  cout << endl;



  

}

Measured memory_bytes: 6272
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  ans += a * (n / (a + b));
  ans += min(n % (a + b), a);
  cout << ans << "\n";
  return 0;
}

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

#define PRINT(x) cout << x << endl;
#define REP(i, n) for(int i = 0; i < n; i++)
#define INF 1e17

using namespace std;
typedef long long ll;

ll g[300][300];
ll dist[300][300];

template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	ll N, M, L;
	ll A, B, C;

	cin >> N >> M >> L;

	REP(i, N) REP(j, N) g[i][j] = dist[i][j] = INF;

	REP(i, M) {
		cin >> A >> B >> C;
		chmin(g[A - 1][B - 1], C);
		chmin(g[B - 1][A - 1], C);
	}

	REP(i, N) g[i][i] = dist[i][i] = 0;

	REP(k, N) REP(i, N) REP(j, N) chmin(g[i][j], g[i][k] + g[k][j]);

	REP(i, N) REP(j, N) if (i != j && g[i][j] <= L) dist[i][j] = 1;

	REP(k, N) REP(i, N) REP(j, N) chmin(dist[i][j], dist[i][k] + dist[k][j]);

	int Q, s, t;
	cin >> Q;

	REP(i, Q) {
		cin >> s >> t;
		if (dist[s - 1][t - 1] == INF) PRINT(-1)
		else PRINT(dist[s - 1][t - 1] - 1);
	}

	return 0;
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N;
vector<string> S;

int main(){
  int N;
  cin >> N;
  vector<int> a(N), b(N), c(N), d(N);
  vector<pair<int, int>> red(N), blue(N);
  REP(i, N){
    cin >> a[i] >> b[i];
    red[i].first = a[i];
    red[i].second = b[i];
  }
  REP(i, N){
    cin >> c[i] >> d[i];
    blue[i].first = c[i];
    blue[i].second = d[i];
  }

  sort(blue.begin(), blue.end());
  int ans = 0;
  REP(i, N){
    int pidx = -1, py = -1;
    REP(j, red.size()){
      if(red[j].first < blue[i].first && red[j].second < blue[i].second){
        if(py < red[j].second){
          pidx = j;
          py = red[j].second;
        }
      }
    }
    if(pidx != -1){
      ans++;
      red.erase(red.begin()+pidx);
    }
  }
  cout << ans << endl;
  

  
  


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll H,N; cin >> H >> N;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  vector<ll> sums(N+1,0);
  rep(i,N) sums[i+1] = sums[i] + A[i];
  if(sums[N]>=H) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#include<bits/stdc++.h>
using namespace std;
int main()
{
   
        string s;
        cin>>s;
        int cnt=0;
        if(s=="RRS")
          cout<<2<<endl;
  		else if(s=="SRR")
          cout<<2<<endl;
  		else if(s=="RRR")
          cout<<3<<endl;
  		else if(s=="SSS")
          cout<<0<<endl;
  		else
          cout<<1<<endl;
        
    return 0;
}


Measured memory_bytes: 3552
#include <stdio.h>
#include <math.h>
struct point{
	double x,y;
};

void koch(int n, struct point a,struct point b){
	if(n==0) return;
	struct point s,t,u;

	double deg = M_PI * 60.0/180.0;

	s.x = (2.0 * a.x + 1.0*b.x)/3.0;
  	s.y = (2.0 * a.y + 1.0*b.y)/3.0;
  	t.x = (1.0 * a.x + 2.0*b.x)/3.0;
  	t.y = (1.0 * a.y + 2.0*b.y)/3.0;
	u.x = (t.x - s.x) * cos(deg) - (t.y - s.y) * sin(deg)+s.x; 
	u.y = (t.x - s.x) * sin(deg) + (t.y - s.y) * cos(deg)+s.y; 
  	
  	koch(n-1,a,s);
  	printf("%.8f %.8f\n",s.x,s.y);
  	koch(n-1,s,u);
  	printf("%.8f %.8f\n",u.x,u.y);
  	koch(n-1,u,t);
  	printf("%.8f %.8f\n",t.x,t.y);
  	koch(n-1,t,b);
}

int main(){
	struct point a,b;
	int n;
	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;
	scanf("%d",&n);
	printf("%.8f %.8f\n",a.x,a.y);
	koch(n,a,b);
	printf("%.8f %.8f\n",b.x,b.y);
	return 0;
}

Measured memory_bytes: 2732
#include<bits/stdc++.h>
using namespace std;
 
#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)
 
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  double A,B,C,D;

  cin >> A >> B >> C >> D;

  if(ceil(C/B) <= ceil(A/D))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
#define MOD 1000000007
int main() {
    int N,M;
    cin >> N >> M;
    if(abs(N-M)>1){
        cout << 0 << endl;
        return 0;
    }
    
    ll Nkaijo = 1;
    ll Mkaijo = 1;
    if(N==M){
        rep(i, 0, N){
            Nkaijo *= (i+1);
            Nkaijo %= MOD;
        }
        ll ans = (2*Nkaijo*Nkaijo)%MOD;
        cout << ans << endl;
    }else{
        rep(i, 0, N){
            Nkaijo *= (i+1);
            Nkaijo %= MOD;
        }
        rep(i, 0, M){
            Mkaijo *= (i+1);
            Mkaijo %= MOD;
        }
        ll ans = (Nkaijo*Mkaijo)%MOD;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int a, b, k;
vector<int> vec;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> a >> b >> k;
	int x = min(a, b);
	for (int i = 1; i <= x; i++) {
		if (b%i || a % i) continue;
		vec.pb(i);
	}
	reverse(vec.begin(), vec.end());
	cout << vec[k - 1] << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f,N=5000;
struct Edge{int fr,to;};
vector<Edge>E;
vector<int>G[N];
bitset<N>Used;
int	Dis[N],Src[N];
void addEdge(const int x,const int y){
	E.push_back((Edge){x,y});G[x].push_back(E.size()-1);
	E.push_back((Edge){y,x});G[y].push_back(E.size()-1);
}
bool bfs(const int St,const int Ed){
	memset(Dis,0x3f,sizeof(Dis));
	queue<int> que;que.push(St);Dis[St]=0;
	while(!que.empty()){
		int t=que.front();que.pop();
		for(int i=0;i<G[t].size();i++){
			Edge tmp=E[G[t][i]];int j=G[t][i],w=j%2;
			if(Dis[tmp.to]>Dis[t]+w&&!Used[j]&&!Used[j^1])
				Dis[tmp.to]=Dis[t]+w,Src[tmp.to]=j,que.push(tmp.to);
		}
	}
	return Dis[Ed]<INF;
}
int dfs(const int St,const int Ed){
	for(int i=Ed;i!=St;i=E[Src[i]].fr)
		Used.set(Src[i]);
	return 1;
}
void solveProblem(const int St,const int Ed){
	int maxFlow=0,reEdge=0;
	queue<int> que;
	while(bfs(St,Ed))
		maxFlow+=dfs(St,Ed);
	cout<<maxFlow<<endl;
	for(int i=1;i<E.size();i+=2)
		if(Used[i])
			reEdge++,que.push(i/2+1);
	cout<<reEdge<<endl;
	while(!que.empty())
		cout<<que.front()<<endl,que.pop();
}
int main(void){
	int n,m,x,y;
	cin>>n>>m;
	for(int i=0;i<m;i++)
		cin>>x>>y,addEdge(x,y);
	cin>>x>>y;
	Used.reset();
	solveProblem(x,y);
	return 0;
}

Measured memory_bytes: 1408