akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

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

	vector<int> vec(N);

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

	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());


	int s = 0;
	int d = 0;
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			d += vec[0];
		}
		else {
			s += vec[i];
		}
	}

	if (s > d) {
		cout << "Yes" << endl;
	}
	else if (s <= d){
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

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

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

using namespace std;

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

char s[103];
ll k;
int main() {
    cin >> s;
    cin >> k;
    REP(i, min(k, 103ll)) {
        if (s[i] == '0')
            break;
        if (s[i] != '1') {
            cout << s[i];
            return 0;
        }
    }
    cout << 1;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N;
int ans;

int main()
{
    cin >> N;

    int tmp = 0;
    while (N--) {
        int x;
        cin >> x;
        if (x - tmp > 0) {
            ans += (x - tmp);
        }
        tmp = x;
    }

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



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

int main() {
  int k,s,c=0;
  cin>>k>>s;
  for(int i=0;i<=k;i++)
  {
    for(int j=0;j<=k;j++)
    {
      if((s-i-j)<=k &&(s-i-j)>=0)
      {
c++;
      }
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n;
	int a,b;
	int c=0;
	scanf("%d",&n);
	for(a=1;a<10;a++){
		for(b=1;b<10;b++){
			if(a*b==n)
			c=1;
		}
	}
	if(c==1)
	printf("Yes");
	else
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int ans=0;
    vector<int> l;
    for(int i=0; i<=min(k,n); ++i){
        if(i!=0) l.push_back(v[i-1]);
        vector<int> r=l;
        for(int j=n; j>=n-k+i;--j){
            if(j!=n && (i-1)<j) r.push_back(v[j]);
            int pr=0,cnt=0;
            sort(r.begin(),r.end());
            for(auto u : r){
                if(u<0 && cnt<(k-i-(n-j))){
                    ++cnt;
                    continue;
                }
                pr+=u;
            }
            ans=max(ans,pr);
        }
    }
    cout << ans << "\n";
    return 0;
}   

Measured memory_bytes: 3604
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int Q = sc.nextInt();
		int l;
		int r;
		int[][] sum = new int[n + 2][n + 1];
		for(int i = 0; i <= n + 1; i++)  Arrays.fill(sum[i], 0);
		for(int i = 0; i < m; i++) {
			l = sc.nextInt();
			r = sc.nextInt();
			sum[l][r]++;	
		}
		for(int i = n; i >= 1; i--) {
			for(int j = 1; j <= n; j++) {
				sum[i][j] += sum[i + 1][j] + sum[i][j - 1] - sum[i + 1][j - 1];
			}
		}
		//for(int i = 0; i <= n + 1; i++) {for(int j = 0; j <= n; j++) {System.out.print(sum[i][j] + "\t");}System.out.println();}
		int p, q;
		for(int i = 0; i < Q; i++) {
			p = sc.nextInt();
			q = sc.nextInt();
			System.out.println(sum[p][q]);
		}
	}
}

Measured memory_bytes: 165916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,r,tmp;
    cin >> a >> b;
    if(a<b){
    tmp = a;
    a = b;
    b = tmp;
    }

  /* ユークリッドの互除法 */
    r = a % b;
    while(r!=0){
    a = b;
    b = r;
    r = a % b;
    }

  /* 最大公約数を出力 */
    ll N = b;
    set<ll> primes;
    
    for(auto p : prime_factor(N)) {
        while(p.second--) primes.insert(p.first);
        }
    
    cout << primes.size() + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
typedef long long i64;
int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    long long currentOne=0,currentTwo=0;
    map<int,int> numMap;
    rep(i,N){
        if(A[i]<=currentTwo) continue;
        if(numMap.find(A[i])==numMap.end()) numMap[A[i]]=1;
        else{
            numMap[A[i]]++;
            if(numMap[A[i]]%2==0){
                if(A[i]>=currentOne){
                    currentTwo=currentOne;
                    currentOne=A[i];
                }else currentTwo=A[i];
            }
        }
    }
    cout << currentOne*currentTwo << endl;

    return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


ll dp[60][205000];
int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,k;
    cin >> n >> k;
    rep(i, n){
        cin >> dp[0][i];
        dp[0][i]--;
    }
    rep(i, 59){
        rep(j, n){
            dp[i + 1][j] = dp[i][dp[i][j]];
        }
    }
    int v = 0;
    for(int i = 59; i >= 0; --i){
        ll l = 1LL << i;
        if( l <= k ){
            v = dp[i][v];
            k -= l;
        }
    }
    print(v + 1);


}



Measured memory_bytes: 97628
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll a[100100];
ll b[100100];

int main(){
	cin>>n;
	REP(i,n){
		cin>>a[i];
		b[i]=a[i];
	}
	ll sum=0;
	ll ans=0;
	for(ll i=0;i<n;i++){
		if(i%2==0){
			if(sum+a[i]<=0){
				ans+=1-sum-a[i];
				a[i]+=1-sum-a[i];
			}
			sum+=a[i];
		}else{
			if(sum+a[i]>=0){
				ans+=sum+a[i]+1;
				a[i]-=sum+a[i]+1;
			}
			sum+=a[i];
		}
	}	
	
	sum=0;
	ll anst=0;
	for(ll i=0;i<n;i++){
		if(i%2==1){
			if(sum+b[i]<=0){
				anst+=1-sum-b[i];
				b[i]+=1-sum-b[i];
			}
			sum+=b[i];
		}else{
			if(sum+b[i]>=0){
				anst+=sum+b[i]+1;
				b[i]-=sum+b[i]+1;
			}
			sum+=b[i];
		}
	}
	cout<<min(ans,anst)<<endl;
	return 0;
}

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

bool cmp(pair<ll,ll> a,pair<ll,ll>b){
    return (a.first + a.second) > (b.first + b.second);
}

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

    int n;
    cin >> n;
    vector<pair<ll, ll>> x(n);
    rep(i, n) cin >> x[i].first >> x[i].second;
    ll ans = 0;
    sort(x.begin(),x.end(),cmp);

    rep(i,n){
        if(i%2==0)
            ans += x[i].first;
        else
            ans -= x[i].second;
    }
    cout << ans << endl;

    return 0;
}



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


/********************************************************************/
#define M1 1000000007
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
/********************************************************************/
// const int mx = 1e7 + 5;
const double pi = 3.1415926535;
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
const int mx = 1e5 + 5;
ll freq[mx] = {};


/********************************************************************/
int main() {
	FAST();
	ll n, k;
	cin >> n >> k;
	vi v;
	ll ele;
	while (n--) {
		cin >> ele;
		v.pb(ele);
	}
	sort(v.begin(), v.end());
	ll ans = 0;
	for (int i = 0; i < k; i++)
		ans += v[i];
	cout << ans;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

typedef long long ll;

ll solve(const ll h, const ll w) {
  ll ans = LLONG_MAX;
  REP(i, h/2+1) {
    ll first_seg = w*i;
    ll cut_h = ((h-i)/2) * w;
    ll cut_h_other = w*(h-i) - cut_h;
    ll cut_h_max = max(first_seg, max(cut_h, cut_h_other));
    ll cut_h_min = min(first_seg, min(cut_h, cut_h_other));
    ans = min(ans, cut_h_max - cut_h_min);
    ll cut_w = (h-i) * (w/2);
    ll cut_w_other = (h-i) * w - cut_w;
    ll cut_w_max = max(first_seg, max(cut_w, cut_w_other));
    ll cut_w_min = min(first_seg, min(cut_w, cut_w_other));
    ans = min(ans, cut_w_max - cut_w_min);
  }
  REP(i, w/2+1) {
    ll first_seg = h*i;
    ll cut_h = ((w-i)/2) * h;
    ll cut_h_other = h*(w-i) - cut_h;
    ll cut_h_max = max(first_seg, max(cut_h, cut_h_other));
    ll cut_h_min = min(first_seg, min(cut_h, cut_h_other));
    ans = min(ans, cut_h_max - cut_h_min);
    ll cut_w = (w-i) * (h/2);
    ll cut_w_other = (w-i) * h - cut_w;
    ll cut_w_max = max(first_seg, max(cut_w, cut_w_other));
    ll cut_w_min = min(first_seg, min(cut_w, cut_w_other));
    ans = min(ans, cut_w_max - cut_w_min);
  }
  return ans;
}

int main() {
  ll h, w;
  cin >> h >> w;
  cout << solve(h, w) << endl;
  return 0;
}

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

typedef long long i64;

i64 GCD(i64 a, i64 b)
{
    return ((!b) ? a : GCD(b, a % b));
}

int main()
{
    i64 A, B, C, D;
    int kase;
    cin >> kase ;
    while(kase--)
    {
        cin >> A >> B >> C >> D ;

        if(B > A)
        {
            cout << "No" << endl ;
            continue;
        }
        if(B > D)
        {
            cout << "No" << endl ;
            continue;
        }
        if(C >= B)
        {
            cout << "Yes" << endl ;
            continue;
        }

        //      C < A-x*B+y*D < B
        // =>   A-B < x*B-y*D < A-C
        i64 gcd = GCD(B, D);
        i64 t1 = A - B, t2 = A - C;
        i64 ans = (t2 / gcd) * gcd ;
        if(ans == t2)
            ans -= gcd;
        if(ans > t1)
            cout << "No" << endl;
        else
            cout << "Yes" << endl ;

    }
}


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

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

	for( int i = 0; i < q; i++ ) {
		string X, Y;
		cin >> X >> Y;
		int m = X.size();
		int n = Y.size();
		vector<vector<int>> c( m + 1, vector<int>( n + 1 ) );
		for( int j = 1; j < m + 1; j++ ) {
			for( int k = 1; k < n + 1; k++ ) {
				if( X[j - 1] == Y[k - 1] ) {
					c[j][k] = c[j - 1][k - 1] + 1;
				}
				else {
					c[j][k] = max( c[j][k - 1], c[j - 1][k] );
				}
			}
		}
		cout << c[m][n] << endl;
	}
}



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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int d, c;
  cin >> d >> c;
  int ans = d * c;
  cout << ans << endl;
}



Measured memory_bytes: 3164
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp;
#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.input();
    let mat: Vec<(isize, isize, isize)> = (0..n - 1)
        .map(|_| {
            (sc.input(), sc.input(), sc.input())
        }).collect();

    for i in 0..n {
        let mut time = 0;
        for j in i..n - 1 {
            let (c, s, f) = mat[j];

            let k = f64::max(0.0 as f64, ((time as f64 - s as f64) / f as f64).ceil());
            time = s + k as isize * f;
            time += c;
        }
        println!("{}", time);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
int a[500010],b[500010];
int sm[500010],pm[500010];
int k;
void sort(int s,int e)
{
    if(e-s<2)
        return;
    int m=s+e>>1;
    sort(s,m);
    sort(m,e);
    int p=s,q=m;
    sm[m]=inf;
    pm[m-1]=-inf;
    int i;
    for(i=m;i-->s;)
        sm[i]=min(a[i],sm[i+1]);
    for(i=m;i<e;i++)
        pm[i]=max(a[i],pm[i-1]);
    for(i=s;i<e;i++)
    {
        if(p>=m)
            b[i]=a[q++];
        else if(q>=e)
            b[i]=a[p++];
        else if(sm[p]>=pm[q]+k)
            b[i]=a[q++];
        else
            b[i]=a[p++];
    }
    for(i=s;i<e;i++)
        a[i]=b[i];
    return;
}
int n,i;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        int s;
        cin>>s;
        a[s-1]=i;
    }
    sort(0,n);
    for(i=0;i<n;i++)
        b[a[i]]=i+1;
    for(i=0;i<n;i++)
        cout<<b[i]<<'\n';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 11392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
//---------------
 
void qry(ll x) {
	printf("? %lld\n",x);
	fflush(stdout);
}
void print(ll x) {
	printf("! %lld\n",x);
	fflush(stdout);
}
bool check(ll mid) {
	qry(mid);
	char c;scanf("\n%c",&c);
//	cout<<c<<endl;
	return c=='Y';
}
bool che() {
    ll x=1e16;
    while(x) {
        qry(x);
		char c;scanf("\n%c",&c);
		if(c=='N') return 0;
		x=x/10ll;
    }
    ll y=999999999;
    while(y) {
        qry(y);
		char c;scanf("\n%c",&c);
		if(c=='N') {
		    print(y+1);
            return 1;    
        }
		y=y/10ll;
    }
    print(1);
    return 1;   
}
 
int main() {
    if(che()) return 0;
	ll x=1e16;
	for(;;) {
		qry(x);
		char c;scanf("\n%c",&c);
		if(c=='Y') break;
		x=x/10ll;
	}
	ll l=x*10,r=l*10-1,ans=-1;
	while(l<=r) {
		ll mid=(l+r)/2ll;
		if(check(mid)) {
			ans=mid;
			r=mid-1;
		} else {
			l=mid+1;
		}
	}
	print(ans/10);
	return 0;
}

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

int main() {
	char str[105];
	bool flag_C = false, flag_F = false;
	cin >> str;
	for (int i = 0; i < strlen(str); i++) {
		if (str[i] == 'C')
			flag_C = true;
		else if (flag_C && str[i] == 'F') {
			flag_F = true;
			break;
		}
	}

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

	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;

int main()
{
    int N, L;
    cin >> N >> L;
    v<string> S(N);
    for (int i = 0; i < N; i++)
        cin >> S[i];

    for (int i = 0; i < L; i++)
    {
        for (int j = 0; j < N - 1; j++)
        {
            for (int k = j + 1; k < N; k++)
            {
                string s;
                bool f = true;
                for (int l = 0; l < i; l++)
                {
                    if (S[j][l] != S[k][l])
                        f = false;
                }
                if (S[j][i] > S[k][i] && f)
                {
                    s = S[j];
                    S[j] = S[k];
                    S[k] = s;
                }
            }
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << S[i];
    }

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <string>
#include <map>

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

int main()
{
    i64 n, m;
    cin >> n >> m;
    vector<i64> a(n);
    for (auto &&i : a)
        cin >> i;

    sort(a.begin(), a.end(), greater<i64>());

    vector<i64> b(n+1);
    for (int i = 0; i < n; i++)
        b[i + 1] = b[i] + a[i];

    int a_max = 500000;
    vector<i64> d(a_max);
    for (int i = 0; i < n; i++)
        d[a[i]]++;
    for (int i = a_max - 1; i >= 1; i--)
        d[i - 1] += d[i];

    i64 l = -1;
    i64 r = 500000;
    while (r - l > 1)
    {
        i64 med = (l + r) / 2;
        i64 s = 0;
        for (int i = 0; i < n; i++)
            s += d[max(1LL, med - a[i])];
        if (s >= m) // Σd は単調減少
            l = med;
        else
            r = med;
    }
    // l -> x; r -> x+1.
    // debug1(l, r);

    i64 k = 0;
    i64 f = 0;
    for (i64 i = 0; i < n; i++)
    {
        i64 v = max(0LL, r - a[i]);
        i64 t = max(0LL, min(d[v], m - k));
        k += t;
        f += b[t] + t * a[i];
    }
    // debug(f);
    f += l * (m - k);

    cout << f << endl;

    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

int main() {
    int n; cin>>n;
    vec a(n+2);
    vec b(n+1);
    rep(i,n+1){
        cin>>a[i];
    }

    a[n+1] = 0;

    rep(i,n){
        cin>>b[i];
    }

    b[n] = 0;

    ll sum=0;
    for(int i=0; i<=n; i++){
        int mn;
        mn=min(a[i],b[i]);
        a[i]-=mn; b[i] -= mn;
        int mnn;
        mnn=min(a[i+1],b[i]);
        a[i+1]-=mnn;
        sum+=mn+mnn;
    }
    
    cout<<sum<<endl;
    
}

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

struct turtle{
	double x, y, angle;
};

double rad (double dig){
	return dig * M_PI / 180;
}

void move (struct turtle *t, double len){
	t->x += len * cos (rad (t->angle));
	t->y += len * sin (rad (t->angle));
}

void turn (struct turtle *t, double dig){
	t->angle -= dig;
}

int main(void) {
	int l, d;
	struct turtle *T;

	T = (struct turtle*) malloc (sizeof (struct turtle));
	T->x = 0;
	T->y = 0;
	T->angle = 90;

	while (1){
		scanf ("%d,%d", &l, &d);
		if (l==0 && d==0) break;
		move (T, l);
		turn (T, d);
	}
	printf ("%d\n%d\n", (int)T->x, (int)T->y);
	free (T);
	return 0;
}

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

#define REP(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#define REPN(i, m, n) for(int (i)=(int)(m); (i)<(int)(n); (i)++)
#define REP_REV(i, n) for(int (i)=(int)(n)-1; (i)>=0; (i)--)
#define debug(x) cout << #x << ": " << (x) << endl;

using namespace std;

int main() {

//    ifstream in("C:\\Users\\P218024\\Documents\\Cpp Projects\\abc094\\sample.txt");
//    cin.rdbuf(in.rdbuf());

    int n;
    int a[100001];

    cin >> n;
    REP(i, n) cin >> a[i];

    sort(a, a + n);

    int ans = 0;
    REP(i, n) {
        if (min(a[i], a[n - 1] - a[i]) > min(ans, a[n-1] - ans))
            ans = a[i];
    }

    cout << a[n - 1] << " " << ans << endl;
}



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

//template
typedef long long int ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v,a,b) v.begin(a),v.end(b)
#define in cin>>
#define out cout<<
#define endl <<endl
const ll INF = 10000000000000;

int main() 
{
	string s;
	in s;
	string t;
	in t;
	vector<vector<int>> a(3100, vector<int>(3100,0));
	rep(i, s.size())
	{
		rep(j, t.size())
		{
			if (s.at(i) == t.at(j))
				a.at(i + 1).at(j + 1) = max(a.at(i + 1).at(j + 1), a.at(i).at(j) + 1);
			a.at(i + 1).at(j + 1) = max(a.at(i + 1).at(j + 1), a.at(i + 1).at(j));
			a.at(i + 1).at(j + 1) = max(a.at(i + 1).at(j + 1), a.at(i).at(j + 1));
		}
	}
	string ans = "";
	int i = s.size(), j = t.size();
	while (i > 0 && j > 0)
	{
		if (a.at(i).at(j) == a.at(i - 1).at(j))
		{
			i--;
		}
		else if (a.at(i).at(j) == a.at(i).at(j - 1))
		{
			j--;
		}
		else
		{
			ans = s.at(i - 1) + ans;
			i--;
			j--;
		}
	}
	out ans endl;
}


Measured memory_bytes: 37888
#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() {
    ll N, M;
    cin >> N;
    vector<ll> T(N);
    rep(i,N) cin >> T.at(i);
    cin >> M;
    vector<ll> P(M), X(M);
    rep(i,M) cin >> P.at(i) >> X.at(i);
    ll total = 0;
    rep(i,N) total += T.at(i);
    rep(i,M) cout << total - (T.at(P.at(i)-1) - X.at(i)) << endl;
}



Measured memory_bytes: 3632
function gcd(a, b){
    if(b != 0)
        return gcd(b, a%b);
    else
        return a;
}

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

const main = (input) => {
  input = input.trim()
  const [a, b] = input.split(' ').map(n => Number(n))
  const result = lcm(a, b)
  console.log(result)
  
  
  
  
  
  
  
  
}

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

Measured memory_bytes: 7500
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

n=int(input())
p=[int(input()) for i in range(n)]
lst=[0]*(n+2)
for i in range(n):
    lst[p[-1-i]]=lst[p[-1-i]+1]+1
# print(lst)
print(n-max(lst))

Measured memory_bytes: 79704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a;
  b = a / 1000;
  c = a % 10;
  if ((a - 1000*b) % 111 == 0 || (a - c) % 1110 == 0) 
  cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

const int N = 100000;
const int M = 200000;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i=0; i<n; i++) cout << "ACL";
  cout << endl;
  return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  ll n,cnt=0,a=MAX,b=MAX;cin>>n;
  vll x(n),y(n),m(n);
  rep(i,0,n){cin>>x[i];m[i]=i+1;}
  rep(i,0,n){cin>>y[i];}
  do{
    cnt++;
    if(x==m){a=cnt;}
    if(y==m){b=cnt;}
  }while(next_permutation(m.begin(),m.end()));
  
  out(abs(a-b));
}


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

flg=False
for x in range(N+1):
    for y in range(M+1):
        temp = (N-x)*(M-y) + (x*y)
        if K==temp:
            flg=True
            break
if flg:
    print("Yes")
else:
    print("No")

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

int main(){
  
  string N;
  cin >> N;
  
  if(N.at(0) == N.at(1) && N.at(1) == N.at(2) && N.at(2) ==N.at(0)){
    
    cout << "Yes" << endl;;
  }
  else if(N.at(1) == N.at(2) && N.at(2) == N.at(3) && N.at(3) == N.at(1)){
    
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  
  }
  
}


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

int main(void) {
    long long H;
    cin >> H;
    long long round = 0;
    for (long long i = 1; i <= H; i *= 2) {
        round += i;
    }
    printf("%lld\n", round);

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
total = sum(A)
S = [0]*N
s = 0
for i in range(0,N-1):
    s += A[i]
    S[i] = s
print(min(abs(S[i]-(total-S[i])) for i in range(0, N-1)))



Measured memory_bytes: 24936
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,i,cnt=0;
    cin >> n;
    vector<int>a(n);
    for(i=0;i<n;i++) cin >> a[i];
    for(i=1;i<n-1;i++){
        if(a[i-1]<a[i] && a[i]<a[i+1] || a[i-1]>a[i] && a[i]>a[i+1]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
(defun main ()
  (let ((n (rem (read) 10))
        (ans "bon"))
    (cond ((member n '(2 4 5 7 9))
           (setf ans "hon"))
          ((member n '(0 1 6 8))
           (setf ans "pon")))
    (format t "~a~%" ans)))

(main)
         


Measured memory_bytes: 23508
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const INF: i64 = 1 << 60;

fn main() {
    input!{
        N: usize,
        X: [i64; N],
    }
    let mut ans = INF;
    for p in 1..101 {
        let mut power = 0;
        for i in 0..N {
            power += (X[i] - p) * (X[i] - p);
        }
        chmin!(ans, power);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <memory.h>
int main(void){
  int n,m[5],i,j,f=0;
  int s[8][5];
  while(scanf("%d",&n)!=EOF){
    if(f)
      puts("");
    memset(s,0,sizeof(s));
    for(i=4;i>=0;i--){
      m[i]=n%10;
      n/=10;
    }
    for(i=0;i<5;i++){
      if(m[i]>=5){
	s[0][i]=' ';
	s[1][i]='*';
	m[i]%=5;
      }
      else{
	s[0][i]='*';
	s[1][i]=' ';
      }
    }
    for(i=0;i<5;i++)
      s[2][i]='=';
    for(i=0;i<5;i++){
      for(j=0;j<m[i];j++){
	s[3+j][i]='*';
      }
      s[3+j][i]=' ';
      for(j++;j<5;j++){
	s[3+j][i]='*';
      }
    }
    for(i=0;i<8;i++){
      for(j=0;j<5;j++){
	printf("%c",s[i][j]);
      }
      puts("");
    }
    f=1;
  }
  return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    if (2 * k - 1 > n) printf("-1\n"), exit(0);
    int tmp = k;
    auto print = [&](int a, int b, int c) {
        printf("%d %d %d\n", tmp + a - 1, tmp + n + b - 1, tmp + n + n + c - 1);
    };
    k = (n + 1) >> 1;
    for (int i = 1; i <= k; i++) {
        print(i, n - k + i, i * 2 - 1);
    }
    for (int i = k + 1; i <= n; i++) {
        print(i, i - k, (i - k) * 2);
    }
    return 0;
}
/*
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
4 14
5 15
6 16
7 17
8 11
9 12
10 13
3 4 5 6 7
8 9 10 11 12
13 14 15 16 17
3 10

*/

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int dp[200010];
string s;
map <int, int> f;
int mask[200010];
const int inf = 1e8;

int main (int argc, char const* argv[])
{	
	cin >> s;
	s = "&" + s;
	
	int n = s.size() - 1;
	
	for(int i = 1; i <= n; i++) {
		int c = s[i] - 'a';
		mask[i] = mask[i-1] ^ (1 << c);		
	}
	f[0] = 0;
	dp[0] = 0;
	for(int i = 1; i <= n; i++) {
		dp[i] = inf;
		if(f.find(mask[i]) != f.end()) {
			dp[i] = f[mask[i]] + 1; 
		}
		for(int j = 0; j < 26; j++) {
			if(f.find(mask[i] ^ (1 << j)) != f.end()) {
				dp[i] = min(dp[i], f[mask[i] ^ (1 << j)] + 1);
			}
		}
		if(f.find(mask[i]) == f.end()) {
			f[mask[i]] = dp[i];
		} else {
			f[mask[i]] = min(f[mask[i]], dp[i]);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 11328
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var cs []byte
	fmt.Scan(&cs)
	var cnt int
	jp := n - 1
	for i := 0; i < n-1; i++ {
		if cs[i] == 'W' {
			for j := jp; j > i; j-- {
				jp = j - 1
				if cs[j] == 'R' {
					cnt++
					break
				}
			}
		}
		if i >= jp {
			break
		}
	}

	fmt.Println(cnt)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


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

const int MAX_N=1e5+10;
int N;
ll K;
map<int, ll> h;
int a[MAX_N],b[MAX_N];

void solve()
{
	for(int i=0;i<N;++i){
		h[a[i]]+=b[i];
	}
	ll cur = 0;
	for(const auto& p : h){
		int aa=p.first;
		ll bb =p.second;
		if(cur+bb<K)cur+=bb;
		else{
			cout << aa << '\n';
			return;
		}
	}
}

int main()
{
	cin >> N >> K;
	for(int i=0;i<N;++i){
		cin >> a[i] >> b[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

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

int main(void) {
    string s; cin >> s;
    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var H, W int

func main() {
	fmt.Scan(&H, &W)
	reader := bufio.NewReaderSize(os.Stdin, 10000000)

	q := make([][]int, 0)
	m := make([][]int, H)

	for i := 0; i < H; i++ {
		line, _, _ := reader.ReadLine()
		m[i] = make([]int, W)

		for j, v := range line {
			if string(v) == "#" {
				m[i][j] = 1
				q = append(q, []int{i, j})
			}
		}
	}
	fmt.Println(bfs(q, m) - 1)
}

func bfs(q [][]int, m [][]int) (ans int) {

	for len(q) != 0 {
		ans++
		len := len(q)

		for i := 0; i < len; i++ {
			y, x := q[0][0], q[0][1]
			q = append(q[1:])

			if 0 <= y+1 && y+1 < H && m[y+1][x] == 0 {
				m[y+1][x] = 1
				q = append(q, []int{y + 1, x})
			}
			if 0 <= y-1 && y-1 < H && m[y-1][x] == 0 {
				m[y-1][x] = 1
				q = append(q, []int{y - 1, x})
			}
			if 0 <= x+1 && x+1 < W && m[y][x+1] == 0 {
				m[y][x+1] = 1
				q = append(q, []int{y, x + 1})
			}
			if 0 <= x-1 && x-1 < W && m[y][x-1] == 0 {
				m[y][x-1] = 1
				q = append(q, []int{y, x - 1})
			}
		}

	}
	return
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }


Measured memory_bytes: 137600
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	weathers := []string{"Sunny", "Cloudy", "Rainy"}
	switch s {
	case weathers[0]:
		fmt.Println(weathers[1])
	case weathers[1]:
		fmt.Println(weathers[2])
	case weathers[2]:
		fmt.Println(weathers[0])
	default:
	}
}

Measured memory_bytes: 512
#include<atcoder/all>
using namespace atcoder;

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int N, K; scanf("%d%d", &N, &K);
    LL A[50][50]; rep(y, N) rep(x, N) { int a; scanf("%d", &a); A[x][y] = a; }
    LL INF_A = 1000000001;

    int I_row0, I_col0, s, t, nV = 0; {
        I_row0 = nV; nV += N;
        I_col0 = nV; nV += N;
        s = nV++;
        t = nV++;
    }

    mcf_graph<LL, LL> G(nV);
    rep(i, N) G.add_edge(s, I_row0 + i, K, 0);
    rep(x, N) rep(y, N) G.add_edge(I_row0 + y, I_col0 + x, 1, INF_A - A[x][y]);
    rep(i, N) G.add_edge(I_col0 + i, t, K, 0);
    G.add_edge(s, t, (LL)N * K, INF_A);

    auto F = G.flow(s, t, (LL)N * K);
    LL ans = F.first * INF_A - F.second;
    printf("%lld\n", ans);

    char ansG[50][50]; rep(y, N) rep(x, N) ansG[x][y] = '.';
    auto E = G.edges();
    for (auto e : E) {
        if (!(I_row0 <= e.from && e.from < I_col0)) continue;
        if (e.flow == 0) continue;
        ansG[e.to - I_col0][e.from - I_row0] = 'X';
    }
    rep(y, N) {
        rep(x, N) printf("%c", ansG[x][y]);
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 4104
import math
import time

TEST = True
TEST = False


MOD = 10**9+7
n, m = map(int, input().split())
#start = time.time()

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]

for i in range(2, 150000):
    fac.append(fac[i-1] * i % MOD)
    inv.append((MOD-inv[MOD%i]*(MOD//i)) % MOD)
    finv.append(finv[i-1]*inv[i]%MOD)


def binom(n, k):
    ans = (fac[n] * finv[n-k]) % MOD
    return (ans * finv[k]) % MOD


ans = 1
y = m
x = 1
while y > 1:
    if x*x > y:
        ans = (ans*binom(n,1)) % MOD
        break
    x += 1
    exp = 0
    while y % x == 0:
        y /= x
        exp += 1
    ans = (ans*binom(exp+n-1, exp)) % MOD
    if TEST:
        print("x = " + str(x) + ", ans = " + str(ans) )

print(ans)

#runTime = time.time() - start
#print("My answer is  " + str(ans))
#print("The running time is " + str(runTime) + " sec")

Measured memory_bytes: 68588
S = input()
s1, s2 = S[:2], S[2:]

MM = ["%02d"%i for i in range(1, 12+1)]

# 月のフォーマットの可能性
if s1 in MM:
    if s2 in MM:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if s2 in MM:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<int,bool> mp;
  for(int i=0; i<3; i++){
    int x;
    cin >> x;
    if(mp.count(x)){
      continue;
    }
    else{
      mp[x] = true;
    }
  }
  if(mp.size() == 2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main()
{
    int n;
    cin>>n;
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                int g= __gcd(i,j);
                g=__gcd(g,k);
                sum+=g;
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <tuple>

using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;

    vector< vector<int> > wf(N, vector<int>(N, 1000000000));
    vector< tuple<int,int,int> > edge;
    while(M--) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        wf[a][b] = c;
        wf[b][a] = c;
        edge.emplace_back(a, b, c);
    }

    for(int k=0; k<N; k++) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++){
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
                // if(wf[i][j] > wf[i][k] + wf[k][j]) {
                //     ++ans;
                //     // wf[i][j] = wf[i][k] + wf[k][j];
                // }
            }
        }
    }

    int ans = 0;
    for(auto e: edge) {
        int a = get<0>(e);
        int b = get<1>(e);
        int c = get<2>(e);
        if(wf[a][b] != c) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll x,mov,dis;
int main()
{
	cin >>x>>mov>>dis;
	x=abs(x);
	if (x/dis>=mov) cout <<x-dis*mov;
	else
	{
		ll xi=x;
		mov-=x/dis+1;
		x-=(x/dis+1)*dis;
		if (mov%2==0) cout <<abs(x);
		else cout <<xi%dis;
	}
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iterator>
using namespace std;

//https://beta.atcoder.jp/contests/arc083/tasks/arc083_a

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

int dp[31][3001]; //bool dp

//vector<int> v[10001];
//vector<int> v_old[10001];

/*
int ans(int k,int w){
  int i,ind,s=0;
  vector<int>::iterator m;
  if(v[w].size() <= k){
    return accumulate(v[w].begin(),v[w].end(),0);
  }
  REP(i,k){
    m = max_element(v[w].begin(),v[w].end());
    s += *m;
    ind = distance(v[w].begin(),m);
    v[w].erase(v[w].begin()+ind);
  }
  return s;
}
*/

int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  int i,j,ansa,ansb;
  ansa=a*100;
  ansb=0;
  double score=0.0;
  REP(i,31){
    REP(j,3001){
      if(!i){
	dp[i][j] = j==0?1:0;
	continue;
      }
      if(i*100+j>f || i*e < j){
	dp[i][j]=0;
	continue;
      }
      if(a <= i)
	dp[i][j] = (dp[i-a][j] == 1)? 1:0;
      if(b <= i)
	dp[i][j] = (dp[i-b][j] == 1)? 1:max(0,dp[i][j]);
      if(c <= j)
	dp[i][j] = (dp[i][j-c] == 1)? 1:max(0,dp[i][j]);
      if(d <= j)
	dp[i][j] = (dp[i][j-d] == 1)? 1:max(0,dp[i][j]);

      if(dp[i][j] && score < (double)j / (double)(i*100+j)){
	score = (double)j / (double)(i*100+j);
	ansa = i*100+j;
	ansb = j;
      }
    }
  }
  cout << ansa << " " << ansb << endl;
  return 0;
}


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

struct edge{
  int64_t from;
  int64_t to;
  int64_t cost;
};

int main(){
  int64_t N, M, P;
  cin >> N >> M >> P;
  vector<edge> G(M);
  for(int i=0; i<M; i++){
    int64_t a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    c -= P;
    edge add;
    add.from = a;
    add.to = b;
    add.cost = c*-1;
    G.at(i) = add;
  }
  int64_t INF = 1e18;
  vector<int64_t> dist(N,INF);
  dist.at(0) = 0;
  bool negative = false;
  for(int i=0; i<2*N; i++){
    for(int j=0; j<M; j++){
      edge e = G.at(j);
      if(dist.at(e.from) != INF && dist.at(e.to) > dist.at(e.from) + e.cost){
        dist.at(e.to) = dist.at(e.from) + e.cost;
        if(i >= N-1){
          dist.at(e.to) = -INF;
          if(e.to == N-1){
            negative = true;
          }
        }
      }
    }
  }
  if(negative){
    cout << -1 << endl;
  }
  else{
    cout << max((int64_t)0,dist.at(N-1)*-1) << endl;
  }
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 1000;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(1){
		ll n;cin>>n;
		if(n==0)break;
		ll ans;cin>>ans;
		priority_queue<ll> q;
		ll w=ans;
		q.push(-ans);
		FOR(i,0,n-1){
			ll k;cin>>k;
			w += k;
			ans = max(ans,w+q.top());
			ans = max(ans,w);
			q.push(-w);
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3172
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
     	int n = sc.nextInt();
      	long[] a = new long[n];
     	long[] ans = new long[n];
      	long max = 0;
      	for(int i=0;i<n;i++){
          a[i] = sc.nextLong();
          if( a[i] <= max ){
            ans[i] = max - a[i];
          }else{
            max = a[i];
          }
        }
      	long answer = 0;
      	for(int i=0;i<n;i++){
          answer += ans[i];
        }
      	System.out.println(answer);
	}
}

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

int
main(int argc, char *argv[])
{
  int n;
  int *p;
  int i, j;
  int min_p, max_p;
  int w, w_min;

  w_min = 0;
  
  scanf("%d", &n);

  p = (int *) malloc(n * sizeof (int));

  for (i = 0; i < n; i++) {
    scanf("%d", p + i);
    if (i == 0) {
      min_p = p[0];
      max_p = p[0];
    }
    
    if (min_p >= p[i])
      min_p = p[i];
    
    if (max_p <= p[i])
      max_p = p[i];
  }


  for (i = min_p; i <= max_p; i++) {
    w = 0;
    for (j = 0; j < n; j++)
      w += (p[j] - i) * (p[j] - i);

    if (i == min_p)
      w_min = w;
    
    if (w < w_min)
      w_min = w;
  }
  printf("%d\n", w_min);
}
  


Measured memory_bytes: 128
def main():
    from string import ascii_lowercase
    dic = {i: s for i, s in enumerate(ascii_lowercase)}
    N = int(input())
    ans = []

    def dfs(s, mx):
        if len(s) == N:
            ans.append(s)
            return
        else:
            for i in range(mx+2):
                v = s + dic[i]
                mx = max(mx, i)
                dfs(v, mx)
    dfs("a", 0)
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 69256
#include<iostream>
#include<vector>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

int main(){
  int H , W , N, a[10010];
  
  cin >> H >> W;
  
  cin >> N;
  
  for (int i = 0; i < N; ++i) cin >> a[i];
  
	vector<vector<int> > res(H, vector<int>(W, 0));
 
	int x = 0, y = 0;
	for (int i = 0; i < N; ++i) {
	  for (int j = 0; j < a[i]; ++j) {
		res[x][y] = i+1;
		++y;
		if (y == W) {
		  ++x, y = 0;
		}
	  }
	}
	for (int i = 0; i < H; ++i) {
	  if (i & 1)
        
		reverse(res[i].begin(), res[i].end());
      
	}
	for (int i = 0; i < H; ++i) {
	  for (int j = 0; j < W; ++j) {
		cout << res[i][j];
		if (j != W-1) cout << " ";
	  }
	  cout << endl;
	}
						
  }



Measured memory_bytes: 384