akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> ii;
typedef std::pair<int, ii> iii;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<ii> vii;
typedef std::vector<iii> viii;
const int INF=10000000;
#define pb(a) push_back(a)
#define m0(x) memset(x,-1,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define all(x) (x).begin(), (x).end()
const ll mod=1e9+7;
ll fact[1005];
ll rfact[1005];
ll memo[1005][1005];
int N,A,B,Ca,D;

ll pow(ll base, ll exp) {
  if(exp==0) return 1;
  if(exp&1) return (base*pow(base,exp-1))%mod;
  else return pow((base*base)%mod,exp/2);
}


ll inv(ll n){ return pow(n,mod-2); }

void initialize(){
  fact[0] = 1;
  for(ll n = 1; n <= N; n++)
    fact[n] = (fact[n-1]*n)%mod;
}


ll dp(ll n, ll curr){
  //cerr<<n<<" "<<curr<<endl;
  if (n==0) return 1;
  else if (n<0 or curr>B) return 0;
  else {
    if (memo[n][curr]==-1){
      ll ans=dp(n,curr+1);

      for (ll count=Ca; count<=D and count*curr<=n; count++){
        
          ll num=fact[n];
          ll denom=(pow(fact[curr],count)*fact[n-count*curr])%mod;
          denom=(denom*fact[count])%mod;
          denom=inv(denom);
 
          ll temp=dp(n-count*curr,curr+1);
          temp=(temp*num)%mod;
          temp=(temp*denom)%mod;
 
          ans=(ans+temp+mod)%mod;
      }
    memo[n][curr]=ans;
    }
    return memo[n][curr];
  }

}





int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  
  memset(memo,-1,sizeof(memo));
  cin >> N >> A >> B >> Ca >> D;
  initialize();
  cout<<dp(N,A);
  
  

  



}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF 1e15

ll N,A,B,C,D;

ll dfs(map<ll,ll> &memo, ll x)
{
    if (memo.count(x)) return memo[x];
    ll ret=INF;
    chmin(ret, dfs(memo,(x-x%2)/2) + x%2*D + A);
    chmin(ret, dfs(memo,(x+x%2)/2) + x%2*D + A);
    chmin(ret, dfs(memo,(x-x%3)/3) + x%3*D + B);
    chmin(ret, dfs(memo,(x+3-x%3)/3) + (3-x%3)*D + B);
    chmin(ret, dfs(memo,(x-x%5)/5) + x%5*D + C);
    chmin(ret, dfs(memo,(x+5-x%5)/5) + (5-x%5)*D + C);
    if (D<=INF/x) chmin(ret, x*D);
    return memo[x]=ret;
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin>>t;
    while(t--){
        cin>>N>>A>>B>>C>>D;
        map<ll,ll> memo;
        memo[0]=0; memo[1]=D;
        cout<<dfs(memo,N)<<"\n";
    }
    return 0;
}


Measured memory_bytes: 4608
#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>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s[0] == '9' || s[1] == '9') cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
#define rep_one(i, n) for(int i=1; i<n; i++)
using namespace std;
typedef long long ll;


int main(){
    int n; cin >> n;
    if(n%1000 == 0) cout << 0 << endl;
    else cout << 1000-n%1000 << endl;
}

Measured memory_bytes: 3632
#include<cstdio>

using namespace std;

int main() {
	int M, D;
	scanf("%d %d", &M, &D);
	int count = 0;
	for (int m = 1; m <= M; m++) {
		for (int d = 1; d <= D; d++) {
			int d1 = d % 10;
			int d10 = d / 10;
			if (d1 >= 2 && d10 >= 2 && d1 * d10 == m) {
				count++;
			}
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <string>

using namespace std;


int main(void){
	int n = 0;
	cin >> n;
	int *a = new int[n];


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

	for (int i = n - 1; i >= 0; i--){
		cout  << a[i];
		if (i != 0){
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1188
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T, class U> int dcnt(T x, U d) { int c = 0; while (x % d == 0) c++, x /= d; return c; }

int main() {
    int d, n; cin >> d >> n;
    int cnt = 0, ans = 0;
    while (cnt < n) {
        ans++;
        if (dcnt(ans, 100) == d) cnt++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    ll n;
    cin>>n;
    ll ans=0;
    ll d[n];
    for(ll i=0;i<n;++i){
        cin>>d[i];
    }

    for(ll i=0;i<n;++i){
        for(ll j=0;j<n;++j){
            if(i <= j){
                continue;
            }

            ans += d[i]*d[j];
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
// #include <cassert>
#include <cctype>
// #include <cmath>
#include <cstdio>
// #include <cstdlib>
#include <cstring>
// #include <ctime>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define fir first
#define sec second
#define pb push_back
#define pch putchar
#define rg register
#define SZ(_) (int)_.size()
#define SORT(_) std::sort(_.begin(), _.end())
#define LB(_, __) std::lower_bound(_.begin(), _.end(), __)
#define UB(_, __) std::upper_bound(_.begin(), _.end(), __)

typedef long long LL;
typedef std::pair<int, int> Pii;
typedef std::pair<LL, int> Pli;
typedef std::pair<int, LL> Pil;
typedef std::pair<LL, LL> Pll;
typedef std::vector<int> Vi;
typedef std::vector<LL> Vl;
typedef std::map<int, int> Mii;
typedef std::map<LL, int> Mli;
typedef std::map<int, LL> Mil;
typedef std::map<LL, LL> Mll;
typedef std::set<int> Si;
typedef std::set<LL> Sl;

const int kInf = 0x3f3f3f3f, kMod = 1e9 + 7;
const LL kInf64 = 0x3f3f3f3f3f3f3f3f;

template <typename T> inline
void UMin(T & x, const T & y) { if (x > y) x = y; }
template <typename T> inline
void UMax(T & x, const T & y) { if (x < y) x = y; }
inline int Add(int a, int b) { return (a += b) >= kMod ? a - kMod : a; }
inline int Sub(int a, int b) { return (a -= b) < 0 ? a + kMod : a; }
inline int Mul(int a, int b) { return 1ll * a * b % kMod; }
int FPow(int bs, int ex = kMod - 2) {
	int res = 1;
	for (; ex; bs = Mul(bs, bs), ex >>= 1)
		if (ex & 1) res = Mul(res, bs);
	return res;
}

char S[105];
int k;
std::vector<Pii> st;

int main() {
	scanf("%s%d", S, &k);
	int lens = strlen(S);
	int all = 1;
	for (int i = 1; i < lens; ++i)
		all &= S[i] == S[i - 1];
	if (all) {
		printf("%lld\n", 1ll * lens * k >> 1);
		return 0;
	}
	int cur = 0, cnt = 1;
	for (int i = 1; i < lens; i++) {
		if (S[i] == S[i - 1]) ++cnt;
		else {
			st.pb({S[cur] - 'a', cnt});
			cur = i, cnt = 1;
		}
	} st.pb({S[cur] - 'a', cnt});
	LL ans = 0;
	for (int i = 1; i + 1 < SZ(st); ++i)
		ans += st[i].sec >> 1;
	ans *= k;
	if (st[SZ(st) - 1].fir == st[0].fir) {
		ans += st.begin()->sec / 2 + st.rbegin()->sec / 2 +
			(LL)(st.begin()->sec + st.rbegin()->sec) / 2 * (k - 1);
	} else {
		ans += (LL)(st.begin()->sec / 2 + st.rbegin()->sec / 2) * k;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int i,j;
    long sum = 0,ave = 0,cnt = 0;
    while(1){
        if(scanf("%d,%d",&i,&j) != 2){
            break;
        }
        sum += i * j;
        ave += j;
        cnt ++;
    }
    printf("%ld\n%ld\n",sum,(long)(ave / (double)cnt + 0.5));
    return 0;
}

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

int main(){
    
    int a,b,x;
    cin>>x>>a>>b;
    
    if(a-b>=0)cout<<"delicious"<<endl;
    else if(x>=b-a)cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
if n <= 3:
  print(max(a))
  exit()

a = tuple(a)
dp = [[-10**15]*3 for i in range(n)]

dp[0][2] = a[0]
dp[1][2] = a[1]
dp[2][2] = a[0]+a[2]
dp[3][2] = max(a[0],a[1])+a[3]
dp[3][1] = a[0]+a[3]
for i in range(2,n-2):
  if i%2 == 0:
    dp[i+2][2] = dp[i][2]+a[i+2]
    dp[i+2][1] = max(dp[i][1]+a[i+2],dp[i-1][2]+a[i+2])
    dp[i+2][0] = max(dp[i][0]+a[i+2],dp[i-1][1]+a[i+2],dp[i-2][2]+a[i+2])
  else:
    dp[i+2][2] = max(dp[i][2],dp[i][1],dp[i-1][2])+a[i+2]
    dp[i+2][1] = max(dp[i][1]+a[i+2],dp[i-1][2]+a[i+2])
if n%2 == 1:
  c = min(a[0],a[-1])
  dp[n-1][2] -= c
print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))

Measured memory_bytes: 121316
use std::cmp;
use std::io;

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

const SPLIT_DELIMITER: char = ' ';

#[allow(dead_code)]
fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

fn main() {
    let n: usize;
    let mut ans = 0;
    let mut buf;
    input!(n);
    let v1 = input_vector::<usize>();
    let v2 = input_vector::<usize>();

    for z in &v2 {
        ans += *z;
    }
    ans += v1[0];
    buf = ans;

    for z in 1..n {
        buf = buf - v2[z - 1] + v1[z];
        ans = cmp::max(ans, buf);
    }
    p(ans);
}

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

using namespace std;
typedef long long ll;

ll n;
double A[1000];
int main(){
    double up=1;
    double lw=0;

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

    for(int i=0; i<n; i++){
        up *= A[i];
    }

    for(int i=0; i<n; i++){
        lw += up/A[i];
    }

    cout << setprecision(12) << up/lw << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = ReadIntArray();
            int N = nk[0], K = nk[1];
            var S = ReadString();
            for (var i = 0; i < S.Length; i++)
            {
                Console.Write(i + 1 != K ? S[i] : (char) (S[i] - 'A' + 'a'));
            }

            Console.WriteLine();
        }

        //最小公倍数
        static int LCM(int num1, int num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        static long LCM(long num1, long num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        //最大公約数
        static int GCD(int num1, int num2)
        {
            int a = Math.Max(num1, num2);
            int b = Math.Min(num1, num2);
            int mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static long GCD(long num1, long num2)
        {
            long a = Math.Max(num1, num2);
            long b = Math.Min(num1, num2);
            long mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static void Out(object o)
        {
            Console.WriteLine(o);
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }

    class PriorityQueue<T>
    {
    }
}

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

int H, W;
char d[50][50];

int main() {
  cin >> H >> W;

  rep(i,0,H-1) {
    rep(j,0,W-1) {
      cin >> d[i][j];
    }
  }

  vector<int> a = {-1, 0, 1};
  rep(i,0,H-1) {
    rep(j,0,W-1) {
      int cnt = 0;
      for (int k:a) {
        for (int l:a) {
          int h = i + k, w = j + l;
          if (0 <= h && h < H && 0 <= w && w < W) {
            if (d[h][w] == '#') cnt++;
          }
        }
      }
      if (d[i][j] == '.') {
        d[i][j] = cnt + '0';
      }
    }
  }

  rep(i,0,H-1) {
    rep(j,0,W-1) {
      cout << d[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int N, H[20], i, max, cnt;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &H[i]);
	}

	max = H[0];
	cnt = 1;

	for (i = 1; i < N; i++) {
		if (H[i] >= max) {
			max = H[i];
			cnt++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void)
{
    int age, cost;
    cin >> age >> cost;

    if(age < 6){
        cout << "0" << endl;
    }else if(age < 13){
        cout << cost / 2 << endl;
    }else{
        cout << cost << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
/*qsort(array, array_size, sizeof(int), compare_int)*/

void sort_char(char *C, int string_long)
{
	int i;
	int num[string_long];
	for (i = 0; i < string_long; i++) {
		num[i] = (int)C[i];
	}
	qsort(num, string_long, sizeof(int), compare_int);
	for (i  =0; i < string_long; i++) {
		C[i] = (char)num[i];
	}
}
/*sort_char(array, strlen(array))*/

void change_int(int *a, int *b)
{
	int c = *a;
	*a = *b;
	*b = c;
}


void change_char(char *s, char *t)
{
	char u = *s;
	*s = *t;
	*t = u;
}

int diff_abso_value(int a, int b)
{
	if (a >= b)
		return a - b;
	else
		return b - a;
}

int main()
{
	int n;
	scanf("%d", &n);
	printf("%d", n/3);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

template< unsigned mod >
struct RollingHash {
  vector< unsigned > hashed, power;

  inline unsigned mul(unsigned a, unsigned b) const {
    unsigned long long x = (unsigned long long) a * b;
    unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
    asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod));
    return m;
  }

  RollingHash(const string &s, unsigned base = 10007) {
    int sz = (int) s.size();
    hashed.assign(sz + 1, 0);
    power.assign(sz + 1, 0);
    power[0] = 1;
    for(int i = 0; i < sz; i++) {
      power[i + 1] = mul(power[i], base);
      hashed[i + 1] = mul(hashed[i], base) + s[i];
      if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
    }
  }

  unsigned get(int l, int r) const {
    unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
    if(ret >= mod) ret -= mod;
    return ret;
  }

  unsigned connect(unsigned h1, int h2, int h2len) const {
    unsigned ret = mul(h1, power[h2len]) + h2;
    if(ret >= mod) ret -= mod;
    return ret;
  }

  int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = -1, high = len + 1;
    while(high - low > 1) {
      int mid = (low + high) / 2;
      if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
      else high = mid;
    }
    return (low);
  }
};

using RH = RollingHash< 1000000007 >;


int main(){
    string T, P;

  cin >> T;
  cin >> P;
  RH rh(T), rh2(P);
  for(int i = 0; i + P.size() <= T.size(); i++) {
    if(rh.get(i, i + P.size()) == rh2.get(0, P.size())) {
      cout << i << endl;
    }
  }
}



Measured memory_bytes: 11888
#include <stdio.h>
int main(void){
    int no1, no2, no3;
    int tmp = 0;
    scanf("%d %d %d", &no1, &no2, &no3);
    
    tmp = no1;
    if(no1 > no2){
        no1 = no2;
        no2 = tmp;
    }
    
    tmp = no2;
    if(no2 > no3){
        no2 = no3;
        no3 = tmp;
    }
    
    tmp = no1;
    if(no1 > no2){
        no1 = no2;
        no2 = tmp;
    }
    
    printf("%d %d %d\n", no1, no2, no3);
    
    return 0;
}


Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
int main(){
	int n;
	scanf("%d",&n);
	ll sum=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		sum^=a[i];
	}
	if(sum==0)
		puts("Yes");
	else puts("No");
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)

#define BR "\n"
#define SP " "
#define fcout cout << fixed << setprecision(18)

int main() {
  int N, L;
  cin >> N >> L;

  double pi = 3.14159265358979;
  vector<double> T(N);

  rep0(i, N) {
    double t; cin >> t;
    T[i] = 2 * pi * t / L;
  }

  double ansx = 0, ansy = 0;
  rep0(i, N) {
    rep(j, i + 1, N) {
      double t1, t2, c1, c2;
      if (i == j) continue;
      c1 = j - i - 1;
      c2 = N - 2 - c1;
      t1 = (T[i] + T[j]) / 2 + pi;
      t2 = (T[i] + T[j]) / 2;
      ansx += c1 * cos(t1) + c2 * cos(t2);
      ansy += c1 * sin(t1) + c2 * sin(t2);
    }
  }
  ansx = ansx * 6 / N / (N - 1) / (N - 2);
  ansy = ansy * 6 / N / (N - 1) / (N - 2);
  fcout << ansx << SP << ansy << BR;

  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	fmt.Println(min(a, b), max(0, a-(n-b)))
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;

int main(){
	int n,m,k;
	cin>>n>>m>>k;
	printf("%d",min(n*m,k));
	 




    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    long long int start;
    long long int sub_value;

    scanf("%lld %lld", &start, &sub_value);

    long long int result = start % sub_value;

    long long int result2 = llabs(result - sub_value);

    if (result <= result2) {
        printf("%lld\n", result);
    } else {
        printf("%lld\n", result2);
    }
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
 
#include <iostream>
#include <math.h>
#include <vector>
#include <fstream>
#include <iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <queue>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <random>
#include <cassert>
#include <unistd.h>
 
#define ll int
#define ld long double
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pi acos(-1.0)
#define uniq(v) (v).erase(unique((v).begin(),(v).end()),(v).end())
#define fcin(a) ifstream cin(a);
#define fcout(a) ofstream cout(a);
#define inf (1e16)
#define MOD 1000000007

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int n;
    cin >> n;
    cout << (n / 500) * 1000 + (n % 500 / 5) * 5;
    
    
    
    
    
}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <algorithm>
#include <numeric>

int main()
{
  int N;

  std::vector<int> s;
  scanf("%d", &N);
  s.resize(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", s.data() + i);
  }

  auto sum = std::accumulate(s.begin(), s.end(), 0);
  if ( sum % 10 ) { 
    printf ("%d\n",sum);
    return 0;
  } else {
    std::sort(s.begin(), s.end());
    for (auto e: s) {
      if ( e % 10 ) { 
        printf ("%d\n",sum - e);
        return 0;
      }
    }
  }
  
  puts("0");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();

		int train = Math.min(a, b);
		int bus = Math.min(c, d);
		System.out.println(train+bus);
	}

}

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

int main() {
    int na, nb, m;
    cin >> na >> nb >> m;

    auto a = vector<int>(na);
    auto b = vector<int>(nb);
    for (int i = 0; i < na; i++)
        cin >> a[i];
    for (int i = 0; i < nb; i++)
        cin >> b[i];

    auto min_price = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    for (int i = 0; i < m; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        x--, y--;
        auto price = a[x] + b[y] - c;
        min_price = min(min_price, price);
    }

    cout << max(0, min_price);
    return 0;
}


Measured memory_bytes: 1024
import sys

n, m = map(int, sys.stdin.readline().split())
matlist = []
for _ in range(n):
    matlist.append(list([int(i) for i in sys.stdin.readline().split()]))
matlist = sorted(matlist, key=lambda x: x[0])

ans = 0
for c, v in matlist:
    if v >= m:
        ans += c * m
        break
    else:
        ans += c * v
        m -= v

print(ans)


Measured memory_bytes: 23508
def check(w1,w2):
  return w1[-1] == w2[0]

n = int(input())
w = [input() for _ in range(n)]

if len(set(w)) < n:
  print('No')
  exit()
for i in range(n-1):
  if not check(w[i],w[i+1]):
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int A[262144]; //データの2倍の配列の確保が必要
int dfs(int a, int b, int k, int l, int r){
  if(r<=a || b<=l) return 0;
  if(a<=l && r<=b) return A[k];
  int m=(l+r)/2;
  return dfs(a,b,k*2+1,l,m)+dfs(a,b,k*2+2,m,r);
}

int getsum(int a,int b){
  return dfs(a,b,0,0,131072);
}

//配列に値加えていく関数
void update(int i, int x){ 
  i+=(131072-1); //10万を越える表現しやすい数の中で最小
  A[i]+=x;
  while(i){
    i=(i-1)/2;
    A[i]+=x;
  }
}
int n,q;
int com,x,y;

int main(){
  int i;

  cin >> n >> q;

  for(i = 0 ; i < q ; i++){
    cin >> com >> x >> y;
    if(com == 1){
      cout << getsum(x,y+1) << endl;
    }else{
      update(x,y);
    }
  } 

  return 0;
}

Measured memory_bytes: 1960
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    double xs,ys,xt,yt;
    cin>>xs>>ys>>xt>>yt;
    double dx=xs-xt,dy=ys-yt;
    cout<<fixed<<setprecision(10);
    cout<<sqrt(dx*dx+dy*dy)<<endl;
    
}


Measured memory_bytes: 3288
package main

import (
        "fmt"
        "math"
)

func main() {
        var x, a, b int
        fmt.Scan(&x)
        fmt.Scan(&a)
        fmt.Scan(&b)

        xa := math.Abs(float64(x - a))
        xb := math.Abs(float64(x - b))

        if xa < xb {
                fmt.Println("A")
        } else {
                fmt.Println("B")
        }
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
from sys import stdin
from collections import deque


def grid2adj(arr_grid,direction=4):
    def cand(i,j,direction):
        if direction == 4:
            return [[i-1,j],[i+1,j],[i,j-1],[i,j+1]]
        elif direction == 8:
            return [[i-1,j],[i+1,j],[i,j-1],[i,j+1],
                    [i-1,j-1],[i-1,j+1],[i+1,j-1],[i+1,j+1]]
        else:
            print('Error')
    
    M,N = len(arr_grid),len(arr_grid[0])
    arr_con = [[] for i in range(M*N)]
    for i in range(M):
        for j in range(N):
            v = i*N+j
            for _cand in cand(i,j,direction):
                if 0<=_cand[0]<M and 0<=_cand[1]<N:
                    next_v = _cand[0]*N+_cand[1]
                    arr_con[v].append(next_v)
    arr_val = sum(arr_grid,[])

    return arr_con, arr_val


class BFS():
    def __init__(self, con, val=None):
        # 隣接リスト表現
        self.con = con
        self.val = val
        self.N = len(self.con)
        # 始点からの距離
        self.dist = [-1]*self.N
        self.que = deque()

    def clear(self):
        self.dist = [-1]*self.N
        self.que = deque()

    def bfs(self, start_v, sach_v):
        # 初期条件(0-indexed)
        self.dist[start_v] = 0
        self.que.append(start_v)

        while len(self.que)>0:
            v = self.que.popleft()
            for next_v in self.con[v]:
                if self.dist[next_v] != -1:
                    continue
                if self.val[next_v] == 'X':
                    continue
                self.dist[next_v] = self.dist[v] + 1
                self.que.append(next_v)
                if self.val[next_v] == sach_v:
                    return self.dist[next_v]


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H,W,N   = list(map(int,_in[0].split(' ')))  # type:list(int)
    graph = []
    for i in range(H):
        _ = list(_in[i+1])  # type:list(str)
        graph.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    g_con, g_val = grid2adj(graph)
    bfs = BFS(g_con,g_val)

    cnt = 0
    start_v_arr = ['S']+[str(i) for i in range(1,N+1)]
    for i, start_v in enumerate(start_v_arr[:-1]):
        bfs.clear()
        for v,val in enumerate(g_val):
            if val == start_v:
                cnt += bfs.bfs(v,start_v_arr[i+1])
                break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)



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

int main() {
  int N, sum = 0;
  cin >> N;

  // ここにプログラムを追記
  for (int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    sum += r -l + 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int countaround(vector<vector<int> >& mp, int h, int w) {
    int cnt=0;
    int dh[8]={-1,-1,-1,0,1,1,1,0};
    int dw[8]={-1,0,1,1,1,0,-1,-1};

    for(int i=0; i<8; ++i) {
        if(h+dh[i]>=0 && h+dh[i]<(int)mp.size() && w+dw[i]>=0 && w+dw[i]<(int)mp[0].size() && mp[h+dh[i]][w+dw[i]]==0) ++cnt;
    }
    return cnt;
}

bool checkcount(vector<vector<int> >& mp, int h, int w) {
    return countaround(mp,h,w)>=mp[h][w];
}

typedef pair<int,int> P;

int main()
{
    int H,W;
    cin >> H >> W;

    vector<vector<int> > mp,updt;

    mp.resize(H);
    updt.resize(H);

    for(int i=0; i<H; ++i) {
        string instr;
        cin >> instr;

        mp[i].resize(W);
        updt[i].resize(W);
        for(int j=0; j<W; ++j) {
            if(instr[j]=='.') mp[i][j]=0;
            else mp[i][j]=instr[j]-'0';
            updt[i][j]=0;
        }
    }

    queue<P> q[2];
    int idxq=0;

    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            if(checkcount(mp,i,j)) {
                q[idxq].push(P(i,j));
                updt[i][j]=1;
            }
        }
    }

    int dh[8]={-1,-1,-1,0,1,1,1,0};
    int dw[8]={-1,0,1,1,1,0,-1,-1};

    while(true) {
        while(!q[idxq%2].empty()) {
            P p=q[idxq%2].front(); q[idxq%2].pop();
            mp[p.first][p.second]=0;
            for(int i=0; i<8; ++i) {
                if(p.first+dh[i]>=0 && p.first+dh[i]<(int)mp.size() && p.second+dw[i]>=0 && p.second+dw[i]<(int)mp[0].size() &&
                   updt[p.first+dh[i]][p.second+dw[i]]==0 && checkcount(mp,p.first+dh[i],p.second+dw[i])) {
                    q[(idxq+1)%2].push(P(p.first+dh[i],p.second+dw[i]));
                    updt[p.first+dh[i]][p.second+dw[i]]=1;
                }
            }
        }

        ++idxq;
        if(q[idxq%2].empty()) break;
    }

    cout << idxq << endl;

    return 0;
}

Measured memory_bytes: 11012
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
      if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= i;
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

int main(){
  int X;
  std::cin >> X;
  X-=400;
  int sho = X/200;
  int ans = 8-sho;
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    vector<ll> cum(N+1);
    for (int i = 0; i < N; i++) {
        cum[i+1] = cum[i] + A[i];
    }
    auto check = [&](int x) {
        // 幸福度x以上の握手をした時、(happy, cnt)
        ll happy = 0, cnt = 0;
        for (int a : A) {
            int idx = lower_bound(A.begin(), A.end(), x - a) - A.begin();
            cnt += N - idx;
            happy += a * (N-idx);
            happy += cum[N] - cum[idx];
        }
        return make_pair(happy, cnt);
    };
    ll ok = 0; ll ng = 200005;
    while (abs(ng - ok) > 1) {
        ll mid = (ok + ng) >> 1;
        auto p = check(mid);
        if (p.second >= M) ok = mid;
        else ng = mid;
    }
    auto p = check(ok);
    ll ans = p.first;
    ans -= (ll)ok * (p.second - M);
    cout << ans << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

Measured memory_bytes: 4544
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		int k,i,j,p;
		cin>>k;
		int ans=0;
		for(i=1;i<=k;i++)
		{
			for(j=1;j<=k;j++)
				for(p=1;p<=k;p++)
					ans+=__gcd(__gcd(i,j),p);
		}
		cout<<ans;

	}

	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int A, B;

	cin >> A >> B;
	cout << 6 - (A + B) << endl;
}



Measured memory_bytes: 256
def check_current_posi(map_list, h, w):
  _height = len(map_list)
  _width = len(map_list[0])
  if h == -1 or w == -1 or h >= _height or w >= _width:
    # 枠外
    return False

  else:
    if map_list[h][w] == "#":
      # #がある
      return True

    else:
      # #ではない
      return False

# hとwは0から
# 引数の(h,w)の上下左右のマス目を調べる
def check_around(map_list, h, w):
  posi_list = [
    [h - 1, w], #上
    [h, w - 1], #左
    [h, w + 1], #右
    [h + 1, w] #下
  ]

  _result = False

  for check_posi_h, check_posi_w in posi_list:
    if check_current_posi(map_list, check_posi_h, check_posi_w):
      _result = True
      break
  
  return _result
  

# -------------------------------------------------------------------

_input = list(map(int, input().split(" ")))

_height = _input[0]
_width = _input[1]

_input_map = []

result = True

# マス目の情報を読み込む
for h in range(_height):
  _input_map.append(list(input()))

for h in range(_height):
  if result == False:
    break

  for w in range(_width):
    if _input_map[h][w] == "#":
      if check_around(_input_map, h, w):
        continue
      else:
        result = False
        break

if result == False:
  print("No")
else:
  print("Yes")


Measured memory_bytes: 3064
from fractions import gcd


def lcm(x, y):
    return x // gcd(x, y) * y


def extgcd(a, b):
    if b == 0:
        return [1, 0, a]
    x, y, g = extgcd(b, a % b)
    return [y, x - a//b * y, g]


def mod_inverse(a, m):
    x, y, _ = extgcd(a, m)
    return (m + x % m) % m


N = int(input())
A = list(map(int, input().split()))
_lcm = 1
for a in A:
    _lcm = lcm(_lcm, a)
ans = 0
for a in A:
    ans += _lcm * mod_inverse(a, 1000000007)
print(ans % 1000000007)

Measured memory_bytes: 6100
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
	string a;
	cin>>a;
	if(a.length()==2)
		cout<<a;
	else
	{
		reverse(a.begin(),a.end());
		cout<<a;
	}
	return 0 ;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
const ll inf = 1e18;
const ll mod = 1e9 + 7;


int main(){
    string s;
    cin >> s;
    int ans=0;
    int tmp=0;
    rep(i, s.size()){
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i]== 'G'){
            tmp++;
            if(tmp > ans) ans = tmp;
        }else{
            tmp = 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


int main() {
  string N;
  cin >> N;
  ll K;
  cin >> K;
  ll dp[111][5][2]={};
  ll i, j, k;
  
  
  dp[0][0][1]=1;
  for(i=0; i<N.size(); i++) {
    for(j=0; j<=K; j++) {
      
      if(N[i]-'0'>0) {
        
        for(k=1; k<N[i]-'0'; k++)
          dp[i+1][j+1][0]+=dp[i][j][1];
        
        dp[i+1][j+1][1]+=dp[i][j][1];
        dp[i+1][j][0]+=dp[i][j][1];
        
        
        for(k=1; k<10; k++)
          dp[i+1][j+1][0]+=dp[i][j][0];
        
        dp[i+1][j][0]+=dp[i][j][0];
        
        
      }else {
        dp[i+1][j][1]+=dp[i][j][1];
        
        for(k=1; k<10; k++)
          dp[i+1][j+1][0]+=dp[i][j][0];
        
        dp[i+1][j][0]+=dp[i][j][0];
      }
    }
  }
  
  
  pt(dp[N.size()][K][1]+dp[N.size()][K][0]);
  
  
}




















Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    for(int i = 1;i <= 3;i++) {
        if(a != i && b != i) {
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 256
n=int(input());p=[0]*n
for i in range(n*(n-1)//2):
    a,b,c,d=map(int,input().split())
    if c>d:p[a-1]+=3 
    elif c<d:p[b-1]+=3 
    else:p[a-1]+=1;p[b-1]+=1
r=sorted(p,reverse=True)
for q in p:print(r.index(q)+1)

Measured memory_bytes: 6724
S = list(input())
A = S[0]
B = S[1]
C = S[2]
D = S[3]

# op1
for i in range(2):
  for j in range(2):
    for k in range(2):
      total = int(A) + (-1) ** i * int(B) + (-1) ** j * int(C) + (-1) ** k * int(D)
      if total == 7:
        op1 = "+" if i == 0 else "-"          
        op2 = "+" if j == 0 else "-"          
        op3 = "+" if k == 0 else "-"          

ans = A + op1 + B + op2 + C + op3 + D + "=7"

print(ans)

Measured memory_bytes: 3064
from collections import deque
 
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
 
que = deque()
INF = float('inf')
dx = [1, 0, -1, 0]
dy = [0, 1, 0 , -1]            
D = [[INF] * W for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            que.append([i, j])
            D[i][j] = 0
                       
def bfs():
    while len(que) != 0:
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < H and 0 <= ny < W and A[nx][ny] != '#' and D[nx][ny] == INF:
                que.append([nx, ny])
                D[nx][ny] = D[p[0]][p[1]] + 1
    
bfs()

ans = 0
for i in range(H):
    for j in range(W):
        tmp = D[i][j]
        ans = max(ans, tmp)
        
print(ans)

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

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

	vector<int> edge[2*100001];
	int a, b;
	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	int shirube[100001] = {};
	bool visited[100001] = {};
	queue<pair<int, int> > next;
	next.push(make_pair(1, 0));
	int ok = 0;
	while(!next.empty())
	{
		pair<int, int> nowPair = next.front();
		next.pop();
		if(visited[nowPair.first])
		{
			continue;
		}
		int now = nowPair.first;
		int previous = nowPair.second;
		visited[now] = 1;
		++ok;
		shirube[now] = previous;
		for (int i = 0; i < edge[now].size(); ++i)
		{
			next.push(make_pair(edge[now][i], now));
		}
	}
	cout << "Yes" << endl;
	for (int i = 2; i <= n; ++i)
	{
		cout << shirube[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 14672
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,M;
    cin >> N >> M;
    cout << (N*(N-1)/2)+(M*(M-1)/2) << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;

using QWORD = unsigned long long;
using SQWORD = long long;
using DWORD = unsigned int;
using SDWORD = int;
using WORD = unsigned short;
using SWORD = short;
using DOUBLE = double;
using FLOAT = float;

#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define ArrayLength(a)  (sizeof(a) / sizeof(a[0]))

static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }

#define BYTE_BITS   (8)
#define WORD_BITS   (16)
#define DWORD_BITS  (32)
#define QWORD_BITS  (64)

using M_BOOL = bool;
#define M_TRUE (true)
#define M_FALSE (false)

static void printMatrix(DWORD **p, DWORD dwSize)
{
    printf("---\n");
    for (DWORD i = 0; i < dwSize; i++) {
        for(DWORD j = 0; j < dwSize; j++) {
            printf("%5d", p[i*dwSize + j]);
        }
        cout << endl;
    }
    printf("---\n");
}

int main()
{
    DWORD dwInput_N, dwInput_M, dwInput_Q;
    char str[200];

    fgets(str, sizeof(str), stdin);
    dwInput_N = atoi(strtok(str, " "));
    dwInput_M = atoi(strtok(NULL, " "));
    dwInput_Q = atoi(strtok(NULL, " "));

    /* input train */
    static DWORD aadwTrainMap[501][501];
    for (DWORD dwIdx = 0; dwIdx < dwInput_M; dwIdx++) {
        fgets(str, sizeof(str), stdin);
        WORD wCity_L, wCity_R;

        wCity_L = atoi(strtok(str, " "));
        wCity_R = atoi(strtok(NULL, " "));
        aadwTrainMap[wCity_L][wCity_R]++;
    }

    /* calc camsum(Row, Col) */
    for (DWORD dwRow = 1; dwRow <= dwInput_N; dwRow++) {
        DWORD dwSum = 0;
        for (DWORD dwCol = 1; dwCol <= dwInput_N; dwCol++) {
            dwSum += aadwTrainMap[dwRow][dwCol];
            aadwTrainMap[dwRow][dwCol] = dwSum + aadwTrainMap[dwRow-1][dwCol];
        }
    }

    /* input question */
    for (DWORD dwIdx = 0; dwIdx < dwInput_Q; dwIdx++) {
        DWORD dwAnswer;
        fgets(str, sizeof(str), stdin);
        WORD wBegin = atoi(strtok(str, " "));
        WORD wEnd   = atoi(strtok(NULL, " "));

        dwAnswer= (aadwTrainMap[wEnd][wEnd]
                    - aadwTrainMap[wBegin-1][wEnd]
                    - aadwTrainMap[wEnd][wBegin-1]
                    + aadwTrainMap[wBegin-1][wBegin-1]);
        printf("%d\n", dwAnswer);
    }

    return 0;

}



Measured memory_bytes: 1920
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
vector<string> ans;
int N;
void build(string S, int T) {
    if (sz(S) == N) {
        ans.pb(S); return;
    }
    F0R(i, T) {
        char C = 'a' + i;
        string S2 = S + C;
        build(S2, T);
    }
    char C = 'a' + T;
    string S2 = S + C;
    build(S2, T+1);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    cin >> N;
    build("", 0);

    sort(all(ans));
    F0R(i, sz(ans)) {
        cout << ans[i] << endl;
    }
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 7796