akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define abu ios_base::sync_with_stdio(0)
#define said cin.tie(0)
using namespace std;
ll const MOD = 998244353;

void yes(){
    cout<<"YES"<<'\n';
}

void no(){
    cout<<"NO"<<'\n';
}

ll fact(int n){
    ll ans = 1;
    for(int i=2;i<=n;i++){
        ans = (ans*i)%MOD;
    }

    return ans;
}

ll powM(int n, int x){
    if(x==0){
        return 1;
    }
    if(x==1){
        return n%MOD;
    }

    if(x%2==0){
        ll a = powM(n,x/2);
        return (a*a)%MOD;
    }else{
        return (n*powM(n,x-1))%MOD;
    }
}

ll C(int n, int k){
    return (fact(n) * powM((fact(k)*fact(n-k))%MOD,MOD-2))%MOD;
}

ll A(int n, int k){
    return (fact(n) * powM(fact(n-k)%MOD,MOD-2))%MOD;
}
vi g[200100];
int deg[200100];
bool used[200100];
int d[200100];

void dfs(int v){
    used[v] = true;
    for(int i=0;i<g[v].size();i++){
        d[g[v][i]] = max(d[g[v][i]],d[v]+1);
        deg[g[v][i]]--;
        if(deg[g[v][i]]==0){
            dfs(g[v][i]);
        }
    }
}

void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        g[v].pb(u);
        g[v].pb(0);
        deg[u]++;
        deg[0]++;
    }

    for(int i=0;i<=n;i++){
        if(!used[i] && deg[i]==0){
            dfs(i);
        }
    }

    cout<<d[0]<<'\n';

}

int main(){
    abu;
    said;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,l,t,r,ans,arr[1000000];
    string s;
    cin>>s;
    if(s.length()<6)
    {
        cout<<"No";
        return 0;
    }
    if(s[2]==s[3] && s[4]==s[5])
        cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	long long int k, a, b;
	cin >> k >> a >> b;

	if (a - b > 0) {
		long long int p = k - a;
		long long int aa, bb;
		aa = bb = p / (a - b);
		while (aa*a - bb*b < k) {
			if ((aa + 1)*a - bb*b >= k) {
				aa++;
				break;
			}
			else {
				aa++;
				bb++;
			}
		}
		cout << aa + bb << endl;
	}
	else {
		if (a >= k) {
			cout << 1 << endl;
		}
		else {
			cout << -1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
const int INF = (int)1e9 + 7;
using ll = long long;

template<class T>
T knapsack(int N, int W, vector<T> v, vector<int> w) {
    vector<vector<T>> dp(N + 1, vector<T>(W + 1, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
            }
        }
    }
    return dp[N][W];
}

struct Town {
    int x = 0, y = 0;
    unordered_map<string, ll> items;
};

inline int dist(Town& a, Town b = Town()) {
    return abs(a.x - b.x) + abs(a.y - b.y);
}

int main() {
    int N, M, W, T; cin >> N >> M >> W >> T;
    vector<string> i2s(M);
    unordered_map<string, int> s2w, s2p;
    for (int i = 0; i < M; i++) {
        string s; cin >> s; i2s[i] = s;
        cin >> s2w[s] >> s2p[s];
    }
    vector<Town> towns(N);
    for (int t = 0; t < N; t++) {
        int n; cin >> n >> towns[t].x >> towns[t].y;
        while (n--) {
            string s; int q; cin >> s >> q;
            towns[t].items[s] = s2p[s] - q;
        }
    }
    vector<ll> main_v(1 << N, 0); vector<int> main_w(1 << N, INF);
    for (int mask = 1; mask < 1 << N; mask++) {
        vector<int> ids;
        for (int t = 0; t < N; t++) if (mask & (1 << t)) {
            ids.push_back(t);
        }
        vector<ll> sub_v(M); vector<int> sub_w(M);
        for (int i = 0; i < M; i++) {
            sub_w[i] = s2w[i2s[i]];
            for (int t : ids) {
                sub_v[i] = max(sub_v[i], towns[t].items[i2s[i]]);
            }
        }
        main_v[mask] = knapsack(M, W, sub_v, sub_w);
        int& optime = main_w[mask];
        do {
            int tmp = dist(towns[ids.front()]) + dist(towns[ids.back()]);
            for (auto it = ids.begin(); it + 1 < ids.end(); it++) {
                tmp += dist(towns[*it], towns[*(it + 1)]);
            }
            optime = min(optime, tmp);
        } while (next_permutation(ids.begin(), ids.end()));
    }
    cout << knapsack(1 << N, T, main_v, main_w) << endl;
    return 0;
}


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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    ll n; cin >> n;
    VL a(n); rep(i,n) cin >> a[i];

    ll cur = 1;
    rep(i,n){
        if(a[i]==cur) cur++;
    }
    if(cur==1) cout << -1 << endl;
    else cout << n-cur+1 << endl;
    return 0;
}

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

int main()
{
    bool ans[3] = {true, true, true};
    for(int i = 0; i < 2; ++i) {
        int tmp;
        cin >> tmp;
        ans[tmp-1] = false;
    }
    for(int i = 0; i < 3; ++i) if(ans[i]) cout << i+1 << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools

N,M=map(int,input().split())
sw=[list(map(int,input().split())) for _ in range(M)]
p=[int(x) for x in input().split()]
ans=0

for i in itertools.product([0,1],repeat=N):#i...スイッチの状態一覧
    onof=True

    for j in range(M):#j...電球の番号
        j_on_cnt=0#電球jに対するonスイッチの個数
    
        for k in sw[j][1:]:
            j_on_cnt+=i[k-1]
            
        if j_on_cnt%2!=p[j]:#電球jがonかoffなのかを調べる
            onof=False
            break
    if onof:
        ans+=1
        
print(ans)

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

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007


ll fast_expontation(ll x,ll y){
	ll res = 1;
	x = x%mod;
	if(x==0) return 0;

	while(y>0){
		if(y&1) 
			res = (res*x)%mod;
		y = y>>1; //y = y/2;
		x = (x*x)%mod;
	}
	return res;
}


// nCr
ll C(ll n, ll a){
	ll res = 1;
	for(int i=n;i>n-a;i--) res = (res*i)%mod; // X
	for(int i=1;i<=a;i++) res = (res*fast_expontation(i,mod-2))%mod;  // X*Y^(mod-2) == X/Y

	return res;
}

int main(){
	NINJA;
	ll n,a,b;

	cin >> n >> a >> b;
	ll tot = (fast_expontation(2,n)-1)%mod;
	tot = (tot-C(n,a) + mod)%mod;
	tot = (tot-C(n,b)+mod)%mod;

	cout << tot << endl;


	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define rep(i,n) for(long long i = n-1;i>=0;i--)
#define repp(i,m,n) for(long long i = n-1; i >= m; i--)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
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() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    double p;
    double dp[N+1][N+1] = {};
  	dp[0][0] = 1.0;
    REP(i,N){
        cin >> p;
        REP(j,i+1){
            dp[i+1][j+1] += dp[i][j] * p;
            dp[i+1][j] += dp[i][j] * (1.0 - p);
        }
    }
    double ans = 0.0;
    REPP(i,(N+1)/2,N+1) ans += dp[N][i];
    Dcout(ans);
}

Measured memory_bytes: 70528
#include <iostream>
using namespace std;
int main()
{
  int t,n,h,p,u,d;
  cin >> t;
  while(t--){
    cin >> n;
    u = d = 0;
    cin >> p;
    while(--n){
      cin >> h;
      if(h > p && h - p > u) u = h - p;
      else if(h < p && p - h > d) d = p - h;
      p = h;
    }
    cout << u << " " << d << endl;
  }
  return 0;
}

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

string a,b="CF";
int al,bl;

int main(){
    getline(cin,a);
    al=a.length();
    for(int i=0;i<al;i++)
        if(a[i]==b[bl]){
            bl++;
            if(bl==2)
                break;
        }
    if(bl==2) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
    return 0;
}

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

int main(){

  int n, G[100][100], i, j, u, k, v;

  for(i=0; i<100; i++){
    for(j=0; j<100; j++){
      G[i][j] = 0;
    }
  }
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    for(j=0; j<k; j++){
      scanf("%d", &v);
      G[i][v-1] = 1;
    }
  }

  for(i=0; i<n; i++){
    printf("%d", G[i][0]);
    for(j=1; j<n; j++){
      printf(" %d", G[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

const int N = 1e5 + 10;
int parent[N], size[N];

void make(int x){
	parent[x] = x;
	size[x] = 1;
}

int findParent(int x){
	if(x == parent[x])
		return x;
	return parent[x] = findParent(parent[x]);
}


void unionSet(int a, int b){
	a = findParent(a);
	b = findParent(b);
	if(a != b){
		if(size[a] < size[b])
			swap(a,b);
		parent[b] = a;
		size[a] += size[b];
	}
}

vector<int> f[N], b[N];

int32_t main(){
	int n, m, k;
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++)
		make(i);
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		f[x].push_back(y);
		f[y].push_back(x);		
		unionSet(x,y);
	}
	for(int i = 0; i < k; i++){
		int x, y;
		cin >> x >> y;
		b[x].push_back(y);
		b[y].push_back(x);
	}
	vector<int> ans(n+1);
	for(int i = 1; i <= n; i++){
		int leader = findParent(i);
		int cnt = size[leader];
		int rem = 0;
		for(int j = 0; j < (int)f[i].size(); j++){
			if(findParent(f[i][j]) == leader)
				rem++;
		}
		for(int j = 0; j < (int)b[i].size(); j++){
			if(findParent(b[i][j]) == leader)
				rem++;
		}
		ans[i] = cnt - rem - 1;
	}
	
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";

	return 0;
}



Measured memory_bytes: 15220
#include <stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int i;
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int min=a[0],max=a[0];
    long long int sub=0;
    for(i=0;i<n;i++){
        sub += a[i];
        if(min > a[i]){
            min = a[i];
        }
        if(max < a[i]){
            max = a[i];
        }
    }
    printf("%d %d %lld\n",min,max,sub);
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define all(a) a.begin(), a.end()

typedef long long lint;

const lint mod = 1e9 + 7;

lint memo[61][2][2][2];

lint L, R;

lint solve(int pos, bool left, bool right, bool msb) {
    // printf("%d %d %d %d\n", pos, left, right, msb);
    if (pos == -1)
        return 1;
    lint &ret = memo[pos][left][right][msb];
    if (ret != -1)
        return ret;
    ret = 0LL;
    bool lb = (L & (1LL << pos)) ? false : true;
    bool rb = (R & (1LL << pos)) ? true : false;
    // x0, y0
    if (left || lb)
        ret += 1LL * solve(pos - 1, left, rb ? 1 : right, msb);
    // x0, y1
    if ((left || lb) && (right || rb) && msb)
        ret += 1LL * solve(pos - 1, left, right, msb);
    // x1, y1
    if (right || rb)
        ret += 1LL * solve(pos - 1, lb ? 1 : left, right, 1);
    ret %= mod;
    return ret;
}

int main() {
    scanf("%lld%lld", &L, &R);
    memset(memo, -1, sizeof(memo));
    printf("%lld\n", solve(60, 0, 0, 0));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    ll n,x,m; cin >> n >> x >> m;
    vector<ll> ok(m,-1);
    vector<ll> ans(m,0);
    ll now=x;
    ll cnt=0; //kosuu
    while(ok[now]==-1){
        //cout << now << endl;
        ok[now]=cnt;
        ans[cnt+1]=ans[cnt]+now;
        now=(now*now)%m;
        cnt++;
    }
    if(cnt==n){
        cout << ans[n] << endl;
        return 0;
    }
    if(now==0){
        cout << ans[cnt] << endl;
        return 0;
    }
    if(ok[now]==0){
        ll loop=n/cnt;
        ll re=n-loop*cnt;
        ll out=ans[cnt]*loop;
        out+=ans[re];
        cout << out << endl;
        return 0;
    }
    ll out=ans[ok[now]];
    n-=ok[now];
    
    ll loop=n/(cnt-ok[now]);
    ll re=n-loop*(cnt-ok[now]);
    out+=(ans[cnt]-ans[ok[now]])*loop;
    out+=(ans[ok[now]+re]-ans[ok[now]]);
    //rep(i,cnt+1) cout << ans[i] << " ";
    cout << out << endl;
    
}




Measured memory_bytes: 4776
import math
a, b, c = map(float, input().split())
c = c*math.pi/180
S = 0.5*a*b*math.sin(c)
d = (a**2 + b**2 - 2*b*a*math.cos(c))**0.5
L = a + b + d
h = b*math.sin(c)
print (S, L, h, end="\n")


Measured memory_bytes: 5708
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
  
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    
    public static void main (String[] args) {
        FastReader ob = new FastReader();
        long a = ob.nextLong(),b=ob.nextLong(),x=ob.nextLong();
        long count = b/x;
        count-=(a/x);
        if(a%x==0){
            count++;
        }
        System.out.println(count);
    }
    
}

Measured memory_bytes: 23252
import java.util.*;

/**
 * A
 */
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
            System.out.print(array[i]);
            if(i<array.length-1) {
                System.out.print(" ");
            }
        }

        System.out.println();

        sc.close();

        for(int i=1; i<array.length; i++) {
            
            int key = array[i];
            /* insert A[i] into the sorted sequence A[0,...,j-1] */
            int j = i-1;
            while(j>=0 && array[j]>key) {
                array[j+1] = array[j];
                j--;
            }
            array[j+1] = key;

            for(int num=0; num<array.length; num++) {
                System.out.print(array[num]);
                if(num != array.length-1) {
                    System.out.print(" ");
                } else {
                    System.out.println();
                }
            }
        }

    }
}


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


using namespace std;

int main() {

	string s;
	cin >> s;
	bool check=false;
	for(int i=0;i<s.length();i++){
		if(s[i]=='A')
			check=true;
		else if(check and s[i]=='C')
			break;
		else
			check=false;
		if(i==s.length()-1)
			check=false;

	}
	if(check)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (n, m) = input_tuple();
    if n < 2 && m < 2 {
        println!("1");
        return;
    }
    if n < 2 {
        println!("{}", m - 2);
        return;
    }
    if m < 2 {
        println!("{}", n - 2);
        return;
    }
    println!("{}", (n - 2) * (m - 2));
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
vector<int>i;
int u,y;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a=0,b=0,c,d=0,e=0,f=-1,g=0;
  string s,w;
  cin >>a>>b;
  c=1;
  while(1){
    if(c>=b) break;
    d++,c--,c+=a;
  }
  cout <<d<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int length;
  std::string str;
  std::cin >> length >> str;

  int count = 0;
  for (int i = 2; i < length; ++i) {
    if (str.at(i - 2) == 'A' && str.at(i - 1) == 'B' && str.at(i) == 'C') {
      ++count;  
    }
  }
  std::cout << count << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
int main()
{
    long long int t;
    cin>>t;
    int check=1;
   // vector<ll > v;
    unsigned long long int ans=0;
    for(ll i=1;i<=t;i++)
    {
       
       for(ll j=1;j<=t;j++)
       {
          for(ll k=1;k<=t;k++)
          {
              ans+=gcd(i,gcd(j,k));
          }

       }

    }
    cout<<ans;
//   if(check)
//    cout<<"No";
    return 0;
}


Measured memory_bytes: 3636
/*
手打一遍加深印象
首先观察：一个点被消掉满足的条件：它已经在“边界”上，即矩形要独立才能继续对它操作
如果把一个方向上的厚冰块全部都修改,显然不是最优的,
<你可以通过一些操作先使得当前的矩形独立>,最后再修改该矩形内一个方向上的所有厚冰块。
考虑 ,设dp[x1][y1][x2][y2]表示该矩形要独立要进行的最小操作数,从外往里转移

Code by zqr.
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
inline LL read(){
	register LL x=0,f=1;register char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<3)+(x<<1)+(c&15),c=getchar();
	return f*x;
}
inline char readc(){
	register char c=getchar();
	while(c==' '||c=='\n'||c=='\t')c=getchar();
	return c;
}

const int MAXN=45;
const int INF=1e9;

int ice[MAXN][MAXN],f[MAXN][MAXN][MAXN][MAXN];
int n,m,hx,hy,ans=INF;

inline int poi(int lx,int ly,int rx,int ry){
	if(lx>rx||ly>ry) return 0;
	return ice[rx][ry]-ice[rx][ly-1]-ice[lx-1][ry]+ice[lx-1][ly-1];
}

int main(){
	n=read(),m=read();
	memset(f,0x3f,sizeof f);
	f[1][1][n][m]=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char c=readc();
			if(c=='P') hx=i,hy=j;
			ice[i][j]=ice[i-1][j]+ice[i][j-1]-ice[i-1][j-1]+(c=='#');//正常的前缀和优化
		}
	}
	for(int i=1;i<=hx;i++)
	for(int j=1;j<=hy;j++)
	for(int o=n;o>=hx;o--)
	for(int p=m;p>=hy;p--){
		ans=min(ans,f[i][j][o][p]+min(min(poi(i,j,hx,hy),poi(i,hy,hx,p)),min(poi(hx,j,o,hy),poi(hx,hy,o,p))));
		for(int s=i;s<=o;s++)
		for(int t=j;t<=p;t++){
			if(s>=hx&&t>=hy)
				f[i][j][s][t]=min(f[i][j][s][t],f[i][j][o][p]+poi(s+1,j,o,t)+poi(i,t+1,s,p));
			if(s>=hx&&t<=hy)
				f[i][t][s][p]=min(f[i][t][s][p],f[i][j][o][p]+poi(i,j,s,t-1)+poi(s+1,t,o,p));
			if(s<=hx&&t<=hy)
				f[s][t][o][p]=min(f[s][t][o][p],f[i][j][o][p]+poi(s,j,o,t-1)+poi(i,t,s-1,p));
			if(s<=hx&&t>=hy)
				f[s][j][o][t]=min(f[s][j][o][t],f[i][j][o][p]+poi(i,j,s-1,t)+poi(s,t+1,o,p));
		}
	}
	printf("%d\n",ans);
}

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

int main(){
  string s;
  cin>>s;
  int n=s.size();
  bool flg=true;
  if(s[0]!='A') flg=false;
  if(s[1]-'A'>=0 && s[1]-'A'<=26) flg=false;
  int cap=0;
  int capc=0;
  for(int i=2;i<n-1;i++){
    if(s[i]-'A'>=0 && s[i]-'A'<=26) cap++;
    if(s[i]=='C') capc++;
  }
  if(s[n-1]-'A'>=0 && s[n-1]-'A'<=26) flg=false;

  if(flg&&cap==1&&capc==1) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
}


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

int main() {
    int n, a, cnt = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a % 2 != 0) cnt++;
    }

    if (cnt % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

int main(){
  long long N, S = 1, s = 1000000007LL;
  cin >> N;
  
  for (int i = 1; i < N+1; i++){
    S = (S * (i % s)) % s;
  }
  
  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 1e6 +9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
ll mod = 1e9+7;
ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
 
int main() {   
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
     
     ll t = 1;
     // cin>>t;
 
     while(t--){
          ll a,b;cin>>a>>b;
          ll x = 1^2^3;
          cout<<(x^a^b);
     }
} 

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vi> data(N + 1);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        data[a].push_back(b);
        data[b].push_back(a);
    }
    vi dist(N + 1, -1);
    queue<int> que;
    dist[1] = 0;
    que.push(1);
    int count = 1;
    while(true) {
        queue<int> quet;
        while(!que.empty()) {
            int v = que.front();
            que.pop();
            for (int x : data[v]) {
                if (dist[x] != -1) {
                    continue;
                }
                dist[x] = count;
                quet.push(x);
            }
        }
        que = quet;
        count++;
        if (count > 2) {
            break;
        }
    }
    if (dist[N] == -1) {
        cout << "IMPOSSIBLE" << endl;
    }
    else {
        cout << "POSSIBLE" << endl;
    }
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<pair<T, T>>& vp) {
	for (int i = 0; i < vp.size(); ++i) {
		s << "(" << vp[i].first << "," << vp[i].second << ")" << ( i+1 == vp.size() ? "" : ",\t" );
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
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...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int n,k;
	cin >> n >> k;
	if (n%k== 0) {
		cout << 0 << endl;
	} else {
		cout << 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
const int INF = 1 << 30;
using namespace std;
#define pp pair<int,int>
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
int n, c[510], s[510], f[510], ans[510] = {};
void hoge(int anspos,int pos, int time2) {
	int time = time2;
	if (anspos == n - 1) { ans[anspos] = 0; return; }
	if (pos == n - 1) { ans[anspos] = time; return; }
	if (s[pos] > time)time = s[pos];
	while ((time-s[pos])%f[pos] != 0)++time;
	time += c[pos];
	//cout << anspos << "," << pos <<","<<time<< endl;
	hoge(anspos, pos + 1, time);
}
int main() {
	cin >> n;
	TFOR(i, n-1) {
		cin >> c[i]>>s[i]>>f[i];
	}
	TFOR(i, n) {
		hoge(i, i, 0);
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long LL;

const int maxn = 2e5 + 5;
LL a[maxn];

int main(){
	int n; scanf("%d",&n);
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	LL sum = 0,cnt = 0,ans = 0;
	int r = 0;
	while(r < n && sum == ans){
		sum += a[++r];
		ans ^= a[r];
	}
	if(sum != ans){
		sum -= a[r];
		ans ^= a[r];
		r--;
	}
	cnt += r;
	for(int l = 2;l <= n;l++){
		sum -= a[l - 1];
		ans ^= a[l - 1];
		while(r < n && sum == ans){
			sum += a[++r];
			ans ^= a[r];
		}
		if(sum != ans){
			sum -= a[r];
			ans ^= a[r];
			r--;
		}
		cnt += (r - l + 1);
	}
	printf("%lld\n",cnt);
}

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

int main(){
    string s;
    cin >> s;

    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    }
    if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }
    if(s == "Rainy"){
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); 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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    vvc<ll> A(3, vl(3));
    vvc<ll> B(3, vl(3));
    rep(i, 3) rep(j, 3) cin >> A[i][j];

    ll N;
    cin >> N;
    rep(n,N){
        ll b;
        cin >> b;
        rep(i,3)rep(j,3){
            if(A[i][j]==b){
                B[i][j] = 1;
            }
        }
    }
    bool isok = false;
    rep(i,3){
        if (B[i][0] && B[i][1] && B[i][2]) isok = true;
        if (B[0][i] && B[1][i] && B[2][i]) isok = true;
    }
    if (B[0][0] && B[1][1] && B[2][2]) isok = true;
    if (B[0][2] && B[1][1] && B[2][0]) isok = true;

    cout << (isok ? "Yes" : "No") << endl;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;


ll solve(ll n, ll sum){
    if(n == 0)  return sum;
    ll res = 0;
    int i = 0;
    int mod = 0;
    while(0 < n){
        res += solve(mod, n+sum);
        mod += (n % 10) * pow(10, i);
        n /= 10;
        i++;
    }
    return res;
}


int main(){
    ll n;
    cin >> n;
    cout << solve(n, 0) << endl;


    return 0;
}

Measured memory_bytes: 384
from collections import  Counter
n = int(input())
s = []
for _ in range(n):
    _s = sorted(input())
    s.append(_s)

chr_cnt = Counter(s[0])
for i in range(1, n):
    kari_chr_cnt = Counter(s[i])
    for key in chr_cnt.keys():
        if key not in kari_chr_cnt.keys():
            chr_cnt[key] = 0
            continue
        chr_cnt[key] = min(chr_cnt[key], kari_chr_cnt[key])
ans = ""
for key in chr_cnt.keys():
    ans += key * chr_cnt[key]
print(''.join(sorted(ans)))



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

int main() {
  int H,W;
  cin >> H >> W;
  
  vector<char> picture(H * W);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> picture.at(i * W + j);
    }
  }
  
  for (int i = 0; i < H + 2; i++) {
    if ((i == 0) || (i  == H + 1)) {
      for (int j = 0; j < W + 2; j++) {
        cout << '#';
        if (j == W + 1) {
          cout << endl;
        }
      }
    } else {
      for (int j = 0; j < W + 2; j++) {
        if (j == 0) {
          cout << '#';
        } else if (j == W + 1) {
          cout << '#' << endl;
        } else {
          cout << picture.at((i - 1) * W + j - 1);
        }
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.1415;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

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

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

ll getGcd(ll a, ll b) {
	if (a < b) {
		ll temp = b;
		b = a;
		a = temp;
	}

	ll r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

int getNum(ll target) {

	int bottom = 0;
	int top = 151;
	while (1 < top - bottom) {
		int middle = (top + bottom) / 2;
		if (false/*target < line[middle]*/)top = middle;
		else bottom = middle;
	}
	return bottom;
}

int main() {

	string S; cin >> S;
	map<int, ll>amari;
	ll kakeru = 1;
	ll currentNumber = 0;
	amari[0] = 1;
	for (int i = S.size() - 1; 0 <= i; --i) {
		ll target = S[i] - 48;
		currentNumber = (currentNumber + (kakeru * target) % 2019) % 2019;
		amari[currentNumber]++;

		kakeru = (kakeru * 10) % 2019;
	}

	ll ans = 0;
	for (auto a : amari) {
		ans += a.second * (a.second - 1) / 2;
	}
	cout << ans << endl;
}




Measured memory_bytes: 5944
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        //99999は門番
        int[] check = {1,4,8,9,16,25,27,32,36,49,64,81,100,121,125,128,144,169,196,216,225,243,256,289,324,343,361,400,441,484,512,529,576,625,676,729,784,841,900,961,1000,99999};

        Scanner sc = new Scanner(System.in);
        int max  = sc.nextInt();

        for (int i = 0; i < check.length; i++) {
            if(max < check[i]){
                System.out.println(check[i - 1]);
                return;
            }
        }
    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{

    int N,f=0;
    char x;
    string W[110]={};

    cin>>N;

    cin>>W[1];
    x=W[1][W[1].length()-1];

    for(int i=2;i<=N;i++){
        cin>>W[i];

        if(x!=W[i][0])f=1;

        //重複チェック
        for(int j=1;j<i;j++){
            if(W[i]==W[j]){
                f=1;
                break;
            }
        }

        //末尾チェック
        if(W[i][0]!=x)f=1;

        //直前末尾更新
        x=W[i][W[i].length()-1];

        if(f==1)break;
    }

    if(f==1){
        cout << "No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

void add_self(int &a,int b)
{
	a+=b;
	a%=MOD;
}
void solve() {
int n;
cin>>n;
ll ans=0;
vector<long long int> v(n);
map<long long int,long long int> mp;
for(int i=0;i<n;i++)
{
	cin>>v[i];
	mp[i]=mp[i-1]+v[i];
	mp[i]%=MOD;
}
for(int i=1;i<n;i++)
{
	ans+=(mp[i-1]*v[i])%MOD;
	ans%=MOD;
}
cout<<ans<<endl;

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int tc=1; //cin >> tc;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }
}


Measured memory_bytes: 17188
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, K = map(int, input().split())
P = list(map(int, input().split()))

P.sort()

print(sum(P[:K]))

Measured memory_bytes: 9692
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,y;
    bool flg = false;
    cin >> n >> y;
    for(int i=0;i<=n;++i){
        for(int j=0;j<=n-i;++j){
            int k = n-i-j;
            if(10000*i+5000*j+1000*k == y){
                flg = true;
                cout << i << " " << j <<  " " << k << endl;
                return 0;
            }
        }
    }
    if(!flg) cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i;
	double ans=0;
    cin>>n>>k;
    for(i=1;i<=n;i++)
        if(i>=k) 
			ans+=1.0/n;
        else
		{
            int tmp=i,cnt=0;
            while(tmp<k)
            {
				tmp*=2;
				cnt++;
			}
            ans+=1.0/n*pow(0.5,(double)cnt);
        }
    cout<<fixed<<setprecision(9)<<ans;
    return 0;
}

Measured memory_bytes: 256
/* 
 * I made this version of code of the solution based on #1612957 and #827239.
 * Thank you very much.
 */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int n, k, A[2000000], C[10001];

int main(void) {

    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%d", &A[i]);
        if (A[i] > k) {
            k = A[i];
        }
        ++C[A[i]];
    }

    for (int i = 0, f = 0; i <= k; ++i) {
        for (int j = 0; j < C[i]; ++j) {
            if (f) {
                printf(" %d", i);
            }
            else {
                f = 1;
                printf("%d", i);
            }
        }
    }
    printf("\n");

    return 0;
}

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

int main(){
int N,D;
cin >> N >> D;
int a = 2*D + 1;
int b = N/a;
int c = N%a;

if(c == 0){
	cout << b << endl;
}
else{
	cout << b+1 << endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <utility>

using namespace std;

const int INF = 1000000007;
const double PI = acos(-1.0);
typedef long long llong;

int main()
{
	int d, c;
	cin >> d >> c;
	cout << d * c << endl;
	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;

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

int main()
{
    int m; cin >> m;
    while(m--)
    {
        string s, ss, se;
        cin >> s;
        set<string> lines;

        for(int i = 1; i < s.size(); i++)
        {
            ss = s.substr(0, i);
            se = s.substr(i, s.size() - i);
            lines.insert( ss + se); lines.insert(se + ss);
            reverse(all(ss));
            lines.insert(ss + se); lines.insert(se + ss);
            reverse(all(se));
            lines.insert(ss + se); lines.insert(se + ss);
            reverse(all(ss));
            lines.insert(ss + se); lines.insert(se + ss);
        }
        cout << lines.size() << endl;
    }

    return 0;
}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    auto A = make_vec<char>(N, N);
    auto B = make_vec<char>(M, M);

    REP(i, N) {
        string s;
        cin >> s;
        REP(j, s.size()) { A[i][j] = s[j]; }
    }
    REP(i, M) {
        string s;
        cin >> s;
        REP(j, s.size()) { B[i][j] = s[j]; }
    }

    REP(i, N) {
        REP(j, N) {
            bool flag = false;
            REP(k, M) {
                REP(l, M) {
                    if (i + k >= N || j + l >= N) {
                        flag = true;
                        break;
                    } else if (A[i + k][j + l] != B[k][l]) {
                        flag = true;
                        break;
                    }
                }
            }
            if (!flag) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
text = STDIN.gets.chomp!
words = text.split(' ')
counts = {}
longest_word = ""
words.each do |word|
  if word.length > longest_word.length then
    longest_word = word
  end
  if counts.has_key?(word) then
    counts[word]+=1
  else
    counts[word]=0
  end
end

max_count=0
most_frequent_word=""
counts.keys.each do |key|
  if max_count < counts[key] then
    most_frequent_word = key
    max_count = counts[key]
  end
end

puts "#{most_frequent_word} #{longest_word}"

Measured memory_bytes: 8712
N = int(input())
shiri = []
flag = 0
for i in range(N):
    tugi = str(input())
    tlist = list(tugi)
    if i!=0:
        if tugi in shiri:
            flag = 1
            break
        else:
            mae = list(shiri[i-1])
            if tlist[0]!=mae[-1]:
                flag = 1
                break
            else:
                shiri.append(tugi)
    else:
        shiri.append(tugi)
if flag == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
def gcd(a, b):
    a = max(a,b)
    b = min(a,b)
    r = a - b
    while(r):
        a = max(b,r)
        b = min(b,r)
        r = a % b
    return b    

N = int(input())
HPs = list(map(int, input().split(' ')))

HPs.sort()

r = HPs[0]
for i in range(1,N):
  r = gcd(HPs[i],r)

print(r)

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

int main()
{
  int n;

  cin >> n;

  if(n %2 == 0)
    cout << n;
  else
  {
    cout << n * 2;
  }
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
const ll atcoder = 1e9 + 7;

#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int main() {
	
	string S, T;
	cin >> S >> T;
	for (int i = S.length() - T.length(); i >= 0; i--) {
		rep(j, T.length()) {
			if (!(S[i + j] == T[j] || S[i + j] == '?')) break;
			if (j == T.length() - 1) {
				S.replace(i, T.length(), T);
				replace(S.begin(), S.end(), '?', 'a');
				cout << S << endl;
				return 0;
			}
		}
	}
	cout << "UNRESTORABLE" << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll x,a[100],tmp=1,ans=0;
    a[0]=1;
    for(int i=1;;i++)
    {
        a[i]=a[i-1]*5;
        if(a[i]>=1000000000000000000)
            break;
    }
    scanf("%lld",&x);
    if(x%2)
    {
        printf("0");
        return 0;
    }
    while(x/a[tmp])
    {
        ans+=x/a[tmp]/2;
        tmp++;
    }
    //printf("%lld\n",ans);
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 384
n = gets.to_i
a = gets.split.map(&:to_i)

a_max = a.max
 a_min = a.min

puts 2 * n - 1
idx = 0
positive = true
if a_min.abs <= a_max
  idx = a.index(a_max)
  for i in 1..n do
    puts "#{idx + 1} #{i}"
  end
  for i in 1..(n - 1) do
    puts "#{i} #{i + 1}"
  end
else
  idx = a.index(a_min)
  for i in 1..n do
    puts "#{idx + 1} #{i}"
  end
  for i in 1..(n - 1) do
    puts "#{n - i + 1} #{n - i}"
  end
end

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>

using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b && a != 0) {
		int m, x, y, f[17][17] = { 0 };
		cin >> m;
		f[1][1] = 1;
		while (m--) {
			cin >> x >> y;
			f[y][x] = -1;
		}
		for (int i = 1; i <= b; ++i) {
			for (int j = 1; j <= a; ++j) {
				if (f[i][j] == -1)
					continue;
				if (i - 1 > 0 && f[i - 1][j] != -1)
					f[i][j] += f[i - 1][j];
				if (j - 1 > 0 && f[i][j - 1] != -1)
					f[i][j] += f[i][j - 1];
			}
		}
		cout << f[b][a] << endl;
	}

	return 0;
}

Measured memory_bytes: 3052