akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define RG register
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define clear(x, y) memset(x, y, sizeof(x))
#define int long long

inline int read()
{
    int data = 0, w = 1; char ch = getchar();
    while(ch != '-' && (!isdigit(ch))) ch = getchar();
    if(ch == '-') w = -1, ch = getchar();
    while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
    return data * w;
}

const int maxn(2e5 + 10);
struct edge { int x, y, w; } e[maxn << 2];
inline int cmp(const edge &lhs, const edge &rhs) { return lhs.w < rhs.w; }
int dis[maxn], n, Q, e_num, fa[maxn], ans;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
template<typename T> inline void chkmin(T &x, const T &y) { if(y < x) x = y; }
inline void add_edge(int x, int y, int w) { e[++e_num] = (edge) {x, y, w}; }

signed main()
{
    n = read(), Q = read(); memset(dis, 0x3f, sizeof dis);
    for(RG int i = 1, a, b, c; i <= Q; i++)
        a = read(), b = read(), c = read(),
        add_edge(a, b, c), chkmin(dis[a], c + 1), chkmin(dis[b], c + 2);
    for(RG int i = 0; i < n; i++) chkmin(dis[i], dis[(i - 1 + n) % n] + 2);
    for(RG int i = 0; i < n; i++) chkmin(dis[i], dis[(i - 1 + n) % n] + 2);
    for(RG int i = 0; i < n; i++) add_edge(i, (i + 1) % n, dis[i]), fa[i] = i;
    std::sort(e + 1, e + e_num + 1, cmp);
    for(RG int i = 1; i <= e_num; i++)
    {
        if(find(e[i].x) == find(e[i].y)) continue;
        fa[find(e[i].x)] = find(e[i].y); ans += e[i].w;
    }
    printf("%lld\n", ans);
    return 0;
}
//rtggsgs

Measured memory_bytes: 17664
#include <iostream>

using namespace std;

int N;

void dfs(string s, char mx ){
    if(s.size() == N){
        cout << s << endl;
    }else{
        for(char c = 'a'; c <= mx; c++){
            dfs(s+c, (c == mx) ? (char)(mx+1) : mx);
        }
    }
}

int main(){
    cin >> N;
    dfs("",'a');
    
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

int main()
{
	char s[][5] = {"AC", "WA", "TLE", "RE"};

	int c[4];
	memset(c, 0, sizeof(c));
	int n;
	scanf("%d", &n);
	while (n--) {
		char str[4];
		scanf("%s", str);
		for (int i = 0; i < 4; i++)
			if (strcmp(s[i], str) == 0) c[i]++;
	}

	for (int i = 0; i < 4; i++)
		printf("%s x %d\n", s[i], c[i]);
	return 0;
}


Measured memory_bytes: 3228
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define  FIFO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define  inf 2e18
#define  mod 1000000007
#define  bg begin()
#define  en end()
#define  ll long long int
#define  pb push_back
#define  mp make_pair
#define  pii pair<int,int>
#define  pll pair<ll,ll>
#define  vi vector<int>
#define  vll vector<long long int>
#define  vpll vector<pair<long long int,long long int> >
#define  vpii vector<pair<int,int> >
#define  vstr vector<string>
#define  mpii map<int ,int>
#define  mpll map<long long int,long long int >
#define  max3(a,b,ser) max(a,max(b,ser))
#define  min3(a,b,ser) min(a,min(b,ser))
#define  setbits(x)  __builtin_popcountll(x)
#define  zerobits(x) __builtin_ctzll(x) //zeros after rightmost set bit
#define  w(t) ll t; cin>>t; while(t--)
#define  vin(v,m) for(int i=0;i<m;i++){ll x;cin>>x; v.pb(x);}
#define  for0(i,m) for(int i=0;i<m;i++)
#define  for1(i,m) for(int i=1;i<=m;i++)
#define  forn(i,a,b) for(int i=a;i<=b;i++)
#define  forv(it,v) for(auto it=v.begin();it!=v.end();it++)
#define  mem(a,val) memset(a,val,sizeof(a))
#define  Sort(vec) sort(vec.begin(),vec.end())
#define  RSort(vec) sort(vec.rbegin(),vec.rend())
#define  eb emplace_back
#define  bs binary_search
#define  lb(v,a) lower_bound(v.begin(),v.end(),a)
#define  ub(v,a) upper_bound(v.begin(),v.end(),a)
#define  deb1(x) cerr<<#x<<": "<<x<<" "<<endl
#define  deb2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define  deb3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define  deb4(a, b, ser, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#ser<<": "<<ser<<" | "<<#d<<": "<<d<<endl
#define  FF first
#define  SS second
#define  yes "YES"
#define  no "NO"
#define  PI 3.141592653589793238462643383279502884L
#define  printv(v) for(auto it=v.bg;it!=v.en;it++) cout<<*it<<" "<<endl;
// find_by_order(p)  returns iterator to kth element starting from 0;
// order_of_key(p) returns count of elements strictly smaller than p;
//order of key returns the index if the element was present.
template <typename T>
using orderedset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll Ceil(ll a, ll b) {return a / b + (a % b != 0);}
ll fastModExp(ll a, ll b) { ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll Logn(ll m, ll r) {return (m > r - 1) ? 1 + Logn(m / r, r) : 0;}
// 2- Dimensional vector:- vector<vector<int> > v(m, vector<int> (26, 0));
// Add mod when using mod(avoid -)
int n, m, k, s = 0;
map<pii, int> mpx;
bool vis[10000][10000];
vector<vector<string> > v;
int cnt = 0;


int main()
{
    int l, r, d;
    cin >> l >> r >> d;
    ll cnt = 0;
    int a = l;
    while (a <= r)
    {
        if (a % d == 0)
            cnt++;
        a++;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3632
use std::cmp;

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let vec_str: Vec<String> = s.trim().split_whitespace().map(|x| x.to_string()).collect();
    let N = vec_str[0].parse::<i32>().unwrap();
    
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let vec_str: Vec<String> = s.trim().split_whitespace().map(|x| x.to_string()).collect();
    let mut a_vec: Vec<i32> = vec_str.iter().map(|x| x.parse::<i32>().unwrap()).collect();

    let mut max = 0;

    a_vec.sort();

    //println!("{:?}", a_vec);
    println!("{:?}", a_vec.iter().fold(a_vec[0] as f64,|sum, x| (sum + *x as f64)/2.0));



}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
int mod = 998244353;
long dp[3001][3001] = {};

int main(){
    
    int n, s;
    cin >> n >> s;
    
    vector<int> a(n,0);
    rep(i,n) cin >> a[i];
   
    rep(i,n) rep(j,s + 1){
        
        if(i == 0){
            dp[i][0] = 2;
            dp[i][a[i]] = 1;
            
        } else if (j < a[i]){
            dp[i][j] = dp[i - 1][j] * 2;
            
        } else {
            dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i]];
        }
        
        dp[i][j] %= mod;
        
    }
    
    cout << dp[n - 1][s] << "\n";
    
    return 0;
}



Measured memory_bytes: 73520
import java.util.*; 

public class Main{

    static boolean isStrongPalindrome(String s)
    {
        int len=s.length();
        int start;
        int end=s.length();

        for(int i=0;i<s.length()/2;i++)
        {
            if(s.charAt(i)!=s.charAt(len-i-1))
                return false;
        }

        end=(len-1)/2;
        for(int i=0;i<end;i++)
        {
            if(s.charAt(i)!=s.charAt(end-i-1))
                return false;
        }

        start=(len+3)/2;
        end=len;

        for(int i=0;i<end;i++)
        {
            if(s.charAt(i)!=s.charAt(end-i-1))
                return false;
        }
        return true;
    }
    public static void main(String[] args) {
        
        Scanner in =new Scanner(System.in);

        String s = in.next();

        if(isStrongPalindrome(s))
            System.out.println("Yes");
        else
            System.out.println("No");
        
        in.close();
    }
}


Measured memory_bytes: 23764
s = input()
s1 = int(s[:2])
s2 = int(s[2:])


if 1<= s1 <= 12 and 1 <= s2 <= 12:
    print("AMBIGUOUS")
elif 1 <= s1 <= 12:
    print("MMYY")
elif 1 <= s2 <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = (int)1e5 + 10;

int n, a[N];
int dp[N][2];

int solve(int idx, int taken){
   if(idx >= n){
      tr(idx, taken);
      return 0;//(taken == 0) ? 0 : -inf;
   }

   int &ans = dp[idx][taken];
   if(~ans)
      return ans;

   ans = -inf;
   if (taken){
      smax(ans, -a[idx] + solve(idx+1, 0));
      if (idx != n-1){
         smax(ans, a[idx] + solve(idx+1, 1));
      }
   }
   else{
      smax(ans, a[idx] + solve(idx+1, 0));
      if (idx != n-1){
         smax(ans, -a[idx] + solve(idx+1, 1));
      }
   }

   tr(idx, taken, ans);
   return ans;
}

int32_t main(){_

   cin>>n;

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

   memset(dp, -1, sizeof dp); 
   cout<<solve(0, 0);  

   return 0;
}

// Common sense: do smth instead of nothing
// Even a single second counts...
// If other's can do it, even I can do it. It wouldn't be that tough. Let me give it a try.
// Mistakes made in past
// -Ques. ask for max-min => think binary_search, DP, greedy
// -not reading question properly / skipping to read & understand all samples properly & wasting time in wrong direction.
// -Using wrong indexing in nested loops something like a[i], when it is supposed to be a[j](WA)
// -value of const int N is not correct (WA/RTE).
// -Did you memset dp to -1 ?
// -check for small edges cases and work on small test cases manually if WA
// -not deallocating memory to pointers can lead to MLE. Use delete :))
// -not reading problem statements of harder problems E,..., thinking it couldn't be solved, but it isn't the case.
// -Avoid using #define int long long as much as possible when it's dp problem and requires high memory say, O(N^2, N=5000) (MLE)
// -Check Bitwise Operator Precedence 
// -Use pragmas to optimize (by constant factor) when necessary..
// -Think before coding & starting to debug. Have patience to look inside code and actually see how it works

Measured memory_bytes: 7296
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var limit = Convert.ToInt32(input[0]);
        var buy = Convert.ToInt32(input[1]);
        var eat = Convert.ToInt32(input[2]);

        if (buy >= eat) Console.WriteLine("delicious");
        else if (eat - buy <= limit) Console.WriteLine("safe");
        else Console.WriteLine("dangerous");
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    unsigned long long n;
    ll a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    ll minPort = min(a,min(b,min(c,min(d,e))));
    if(n % minPort == 0)cout << n/minPort + 4;
    else cout << n/minPort + 5;



}

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

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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main() {
    int n; cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s; cin >> s;
        mp[s]++;
    }
    int m; cin >> m;
    rep(i, m) {
        string t; cin >> t;
        mp[t]--;
    }
    int ans = 0;
    for(pair<string, int> p : mp) {
        chmax(ans, p.second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N =int(input())
s = input()
r = 0
b = 0
for i in range(N):
    if s[i:i+1] == "R":
        r += 1
    
    elif s[i:i+1] == "B":
        b += 1
if r > b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;



int main() {
int a,b,c;
  in(a>>b>>c);
  int m = maxx(a,b,c);
  int n = minn(a,b,c);
  int s = a+b+c-m-n;
  out(n*s/2);
}


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

using namespace std;
using ll = long long;


int main()
{
    int x, a, b;
    cin >> x >> a >> b;

    if(b <= a){
        cout << "delicious" << endl;
    }else if(b <= a + x){
        cout << "safe" << endl;
    }else cout << "dangerous" << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> price(n); 
    for (int i=0; i<n; i++){
        cin >> price.at(i);
    }
    int min = price.at(0), ans = price.at(1) - price.at(0);
    for (int i=1; i<n; i++){
        if (ans < price.at(i) - min){
            ans = price.at(i) - min;
        }
        if (price.at(i) < min){
            min = price.at(i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main()
{
    int x, y;
    string s;
    cin>>s;

    for(int i=0; i<s.length(); i++)
    {
        if(s[i]=='A')
        {
            x=i+1;
            break;
        }
    }
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]=='Z')
        {
            y=i+1;
        }
    }
    cout<<y-x+1<<endl;
    return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)
def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N=z()
A = zz()
A.append(0)
diff = [0]*N
prev = 0
A_ = [0]
A_.extend(A)
sum_ = 0
for i in range(len(A_)-1):
    sum_ += abs(A_[i] - A_[i + 1])
    
for i in (range(1,N+1)):
    sub = abs(A_[i]-A_[i-1]) + abs(A_[i] - A_[i+1])
    add = abs(A_[i - 1] - A_[i + 1])
    print(sum_ + add - sub)

Measured memory_bytes: 38520
import math


def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + (n % b)


def build_div(x):
    i = 1
    ret = []
    if x < 0:
        return ret
    while True:
        if i*i > x:
            break
        if x % i == 0:
            ret.append(i)
            ret.append(x//i)
        i += 1
    return sorted(ret)


n = int(input())
s = int(input())
b = -1
if n == s:
    print(n+1)
else:
    for i in range(2, math.ceil(math.sqrt(n))):
        if f(i, n) == s:
            b = i
            print(b)
            break
    if b == -1:
        div = build_div(n-s)
        for i in div:
            if f(i+1, n) == s:
                b = i+1
                print(b)
                break
    if b == -1:
        print(-1)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    int a[n];int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];sum+=a[i];
        
    }
    int max=a[0];
    for(int i=0;i<n;i++)
    {
        if(a[i]>max)
        max=a[i];
    }
    sum-=max;
    if(max<sum)
    cout<<"Yes";
    else
    cout<<"No";
    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 ;
#define ll int
#define ld long double
#define pp pair<ll,pair<ll,ll> >
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell 1000000007
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree<ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
void solve()
{
    vector<ll> v[5] ;
    rep( i , 0 , 3 )
    {
        ll x , y ;
        cin >> x >> y ;
        v[x].pb(y);
        v[y].pb(x);
    }
    ll f1 = 0 , f2 = 0 ;
    rep( i , 1 , 5 )
    {
        if(sz(v[i])==1)f1++;
        if(sz(v[i])==2)f2++;
    }
    if(f1==2&&f2==2)cout << "YES" ;
    else
        cout << "NO" ;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //cin>>t;
    while(t--)
        solve();
    return 0 ;
}


Measured memory_bytes: 256
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;

class Cmp implements Comparator<String[]> {

	@Override
	public int compare(String[] arg0, String[] arg1) {
		// TODO Auto-generated method stub
		if (arg0[0].equals(arg1[0])) {
			return Integer.parseInt(arg1[1])-Integer.parseInt(arg0[1]);
		}
		return arg0[0].compareTo(arg1[0]);
	}
}

public class Main {
	static Scanner sc = new Scanner(System.in);
	static Properties pps = System.getProperties();
	static boolean dbg = true;

	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		// setOut();

		int n = sc.nextInt();
		ns();
		String[][] data = new String[n][];
		for (int i = 0; i < n; i++) {
			String str=sc.nextLine() + " " + (i + 1);

			data[i] =str.split(" ");

		}

		Arrays.sort(data, new Cmp());
		
		for(int i=0;i<data.length;i++) {
			System.out.println(data[i][2]);
		}

	}


	private static void setOut() throws FileNotFoundException {
		sc = new Scanner(new FileInputStream("in.txt"));
		System.setOut(new PrintStream(new FileOutputStream("out.txt")));

	}

	private static void out(List<Integer> l) {
		// TODO Auto-generated method stub
		for (int i : l)
			System.out.println(i);

	}

	private static void out(int[] b) {
		// TODO Auto-generated method stub
		for (int i : b)
			System.out.println(i);

	}

	public static void out(String str) {

		if (dbg)
			System.out.println(str);
	}

	public static void out(int str) {

		if (dbg)
			System.out.println(str);
	}

	public static int ni() {

		return sc.nextInt();

	}

	public static String ns() {

		return sc.nextLine();
	}

	public static int[] ni(int k) {
		int[] res = new int[k];
		for (int i = 0; i < k; i++)
			res[i] = sc.nextInt();
		sc.nextLine();
		return res;
	}

	public static String[] ns(int k) {
		String[] res = new String[k];
		for (int i = 0; i < k; i++)
			res[i] = sc.nextLine();
		return res;
	}

	public static int[][] ni(int a, int b) {
		int[][] res = new int[a][b];
		for (int i = 0; i < a; i++)
			for (int j = 0; j < b; j++)
				res[i][j] = sc.nextInt();
		sc.nextLine();
		return res;
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <deque>
using namespace std;

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

int main(){
  int n;
  int a[2][100];
  int ans;
  cin>>n;
  for(int j=0;j<2;j++){
    for(int i=0;i<n;i++){
      cin>>a[j][i];
    }
  }
  for(int i=1;i<n;i++){
    a[0][i]+=a[0][i-1];
  }
  ans=a[0][n-1]+a[1][n-1];
  for(int i=n-2;i>=0;i--){
    a[1][i]+=a[1][i+1];
    ans=max(ans,a[0][i]+a[1][i]);
  }
  cout<<ans<<endl;
  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

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

	int H=in(),W=in();
	vector<vector<int>> M(H,vector<int>(W,0)),C(H,vector<int>(W,1<<30));
	REP(i,H){
		string S=in<string>();
		REP(j,W){
			if(S[j]=='#') M[i][j]=1;
		}
	}

	if(M[0][0]==1) C[0][0]=1;
	else C[0][0]=0;

	int L=H+W;
	for(int i=1;i<L;i++){
		int us=min(i,W-1);
		int vs=i-us;
		while(us>=0 && vs<H){
			if(vs>0){
				if(M[vs][us] && !M[vs-1][us]) chmin(C[vs][us],C[vs-1][us]+1);
				else chmin(C[vs][us],C[vs-1][us]);
			}
			if(us>0){
				if(M[vs][us] && !M[vs][us-1]) chmin(C[vs][us],C[vs][us-1]+1);
				else chmin(C[vs][us],C[vs][us-1]);
			}
			us--;
			vs++;
		}
	}

	out(C[H-1][W-1]);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
const int N=5005;
char s1[N],s2[N];
int a[N*2],b[N*2],ans,n,cnt1,cnt2;
int main(){
	//freopen("1_71.txt","r",stdin);  
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for (int i=2;i<=n;i++){
		if (s1[i]!=s1[i-1]) a[++cnt1]=i-1;
		if (s2[i]!=s2[i-1]) b[++cnt2]=i-1;
	}
	if (cnt1>cnt2) std::swap(cnt1,cnt2),std::swap(a,b);
	int i,t=(cnt1/4+1)*2;
	for (int i=1;i<=t;i++) b[++cnt2]=n;
	for (int i=cnt2+t;i>t;i--) b[i]=b[i-t];
	cnt2+=t;
	for (int i=1;i<=t;i++) b[i]=0;
	if (s1[1]==s2[1]) i=1;
	else i=0;
	ans=n*n;
	for (;i+cnt1-1<=cnt2;i+=2){
		int sum=0;
		for (int j=1;j<i;j++) sum=sum+b[j];
		for (int j=1;j<=cnt1;j++) sum=sum+abs(a[j]-b[i+j-1]);
		for (int j=i+cnt1;j<=cnt2;j++) sum=sum+n-b[j];
		ans=std::min(sum,ans);
	}
	printf("%d\n",ans);
}

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

int N;

int main(){
    scanf("%d", &N);
    ll a;
    scanf("%lld", &a);
    ll mina = a;
    ll maxa = a;
    for(int i=0; i<N-1; i++){
        scanf("%lld", &a);
        if(maxa < a) maxa = a;
        else if(mina > a) mina = a;
    }
    printf("%lld", maxa - mina);
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
typedef long long int lld;
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;}
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define Error(x) cout<< #x << " = " << (x) <<endl;
#define Error2(a,b) cout<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define Error3(a,b,c) cout<<"("<<#a<<" , "<<#b<<" , "<<#c<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<")\n";
#define Error4(a,b,c,d) cout<<"("<<#a<<" , "<<#b<<" , "<<#c<<" , "<<#d<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<" , "<<(d)<<")\n";
#define errop(a) cout<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll
 
typedef pair<lld,lld> PA;
 
lld powP(lld a,lld b){
    if(b==0) return 1%mod;
    lld k;
    k=powP(a,b/2);
    k=k*k%mod;
    if(b%2==0) return k;
    else return a*k%mod;
}
 
bool bitSet(lld n,lld i){
    if((n&(1LL<<i))!=0) return true;
    else return false;
}
 
lld findGcd(lld a,lld b){
    if(a==0) return b;
    else return findGcd(b%a,a);
}
 
#define lim 300010
#define lim2 200010
#define qqqqqq 210
// Ab :)
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

// vector<lld> G[lim];
// string S[lim];
lld A[lim],B[lim],C[lim];
// map<lld,lld> M;

int main(){
    lld T,i,p,j,l,n,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum,ans,pos,val,countA,indicator;
    sc2(n,k);
    rep(i,1,n) sc(A[i]);
    ans= -1;
    k--;
    rep(i,k+1,n) {
        if(A[i] <= 0) {
            val = abs(A[i-k]);
        }
        else if(A[i-k] >= 0) val = A[i];
        else val = abs(A[i-k]) + A[i] + min(abs(A[i-k]), A[i]);
        // Error4(i,A[i],A[i-k],val);
        if(ans == -1 or val < ans) ans = val;
    }
    prL(ans);
    return 0;
}

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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type, less<int>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e6+1, mod= 998244353;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,res=0; string s;
	cin>>n>>s;
	int dp[n+1][n+1];
	
	memset(dp,0,sizeof dp);
	for(int len=2;len<=n;len++){
		for(int j=n-1;j-len+1>=0;j--){
			int i=j-len+1;
			if(s[i]==s[j]) dp[i][j]= 1+ min( j-i-1,dp[i+1][j+1] );
			else dp[i][j]=0;
		}
	}	
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)res=max(res,dp[i][j]);
	cout<<res;
	
}


Measured memory_bytes: 97920
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

const int mod = 998244353;
struct mint {
    ll x; // using long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll a, b, c, d;
    cin>>a>>b>>c>>d;

    vector<vector<vector<mint>>> dp(c + 2, vector<vector<mint>>(d + 2, vector<mint>(2)));
    dp[a][b][1] = 1;
    rrep(i, a, c + 1) rrep(j, b, d + 1) {
        dp[i][j + 1][1] += dp[i][j][0];
        dp[i][j + 1][1] += dp[i][j][1] * i;
        dp[i + 1][j][0] += (dp[i][j][0] + dp[i][j][1]) * j;
    }
    cout<<dp[c][d][0] + dp[c][d][1]<<endl;
}

Measured memory_bytes: 496168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 998244353;
const double PI = 3.141592653589793;

int main(){
  int n, k;
  cin >> n >> k;
  if(k > (n-1) * (n-2) / 2){
    printf("%d\n", -1);
    return 0;
  }else{
    printf("%d\n", n*(n-1)/2-k);
    for(int i = 2; i <= n; i++){
      printf("%d %d\n", 1, i);
    }
    vector<P> p;
    for(int i = 2; i <= n; i++){
      for(int j = i+1; j <= n; j++){
        p.push_back(P(i, j));
      }
    }
    for(int i = 0; i < (n-1)*(n-2)/2 - k; i++){
      printf("%d %d\n", p[i].first, p[i].second);
    }
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
#define MOD 1000000007

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

  ll n;
  cin >> n;

  ll min = 0;
  ll cnt = 0;
  for (auto i = 0; i < n; i++)
  {
    ll p = 0;
    cin >> p;
    if (i == 0)
    {
      min = p;
      cnt++;
      continue;
    }

    if (p <= min)
    {
      cnt++;
      min = p;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

n, m = map(int, input().split())

prime_list = defaultdict(int)
p = 2
while p <= 10**4.5+5:
    if m%p == 0:
        prime_list[p] += 1
        m //= p
    else:
        p += 1

if m > 1:
    prime_list[m] += 1

MOD=10**9+7

def comb(n, r): 
    if r<0 or r>n: 
        return 0
    r=min(r, n-r)
    res=1
    for i in range(r): 
        res=res*(n-i)%MOD*pow(i+1, MOD-2, MOD)%MOD
    return res

ans = 1
for k in prime_list.keys():
    ans *= comb(prime_list[k]+n-1, prime_list[k])
    ans %= MOD

print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int MAXN = 1e5 + 7;
vector<int>rG[MAXN];
int dp[MAXN], d[MAXN];
int main()
{
    // freopen("longestpath.in", "r", stdin);
    // freopen("longestpath.out", "w", stdout);
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 1, u, v; i <= m; i++)
    {
        scanf("%d%d", &u, &v);
        d[u]++;
        rG[v].push_back(u);
    }
    queue<int>q;
    for (int i = 1; i <= n; i++) if (!d[i]) q.push(i);
    int ans = 0;
    while (q.size())
    {
        int u = q.front(); q.pop();
        for (int i = 0; i < rG[u].size(); i++) 
        {
            int v = rG[u][i];
            ans = max(ans, dp[v] = max(dp[v], dp[u] + 1));
            d[v]--; if (!d[v]) q.push(v);
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
using namespace std;
#define int long long
signed main(){
	int n,t;
	cin >> n >> t;
	int maxLen = 0;
	int sum = 0;
	int offset = 0;
	int diff = 0;
	for(int i = 0 ; i < n ; i++){
		int x;
		cin >> x;
		if( maxLen < x ){
			offset = sum;
			maxLen = x;
			diff = 0;
		}else{	
			diff += x; 
		}
		sum += x;
		int l = 1, r = 1e9 + 10;
		while(l != r){
			int m = (l+r) / 2;
			int tm = offset + maxLen * m + diff;
			if( tm <= t ){
				l = m + 1;
			}else{
				r = m;
			}
		}
		cout << l << endl;
	}
	
}

Measured memory_bytes: 3088
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	string s;
	string t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
lli fun(lli a)
{
    lli s = 0;
    for (int i = 1; i * i <= a; i += 1)
    {
        if (a % i == 0)
        {
            lli b = a / i;
            s += 1;
            if (b != i)
            {
                s += 1;
            }
        }
    }
    return s;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t;
    cin >> t;
    vector<lli> v;
    lli n = t;
    // lli ans = 0;
    vector<lli> vv(10000001, 1);
    for (int i = 2; i < 10000001; i++)
    {
        for (int j = i; j < 10000001; j += i)
        {
            vv[j] += 1;
        }
    }
    lli ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans += (i * vv[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 81340
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll a, b, c;

int main() {
    fast_io; cout_precision;
    cin >> a >> b >> c;
    cout << ((2 * max(a, max(b, c)) == a + b + c) ? "Yes" : "No") << endl;
}

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

//#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

signed main() {
	int n, m; 
	while (cin >> n >> m) {
		V imos(n + 1);
		rep(i, m) {
			int c, d;
			cin >> c >> d;
			int a = n - d, b = n - c;
			imos[a]++;
			imos[b]--;
		}
		rep(i, 1, n + 1) imos[i] += imos[i - 1];
		int ans = n + 1;
		rep(i, n) ans += !!imos[i] * 2;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3112
N, M = map(int, input().split())
a = 0
b = 0
sp = dict()
for _ in range(M):
    s, p = input().split()
    if int(s) not in sp.keys():
        sp[int(s)] = [p]
    else:
        sp[int(s)].append(p)
        
a = 0
b = 0
for i, result in sp.items():
    if "AC" in result:
        a += 1
        b += result.index("AC")
    else:
        continue
print(a, b)

Measured memory_bytes: 28100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] T = new int[N+1];
		int sum = 0;
		for (int i = 1; i <= N; i++) {
			T[i] = sc.nextInt();
			sum+= T[i];
		}

		int M = sc.nextInt();
		int[] P = new int[M+1];
		int[] X = new int[M+1];
		for (int i = 1; i <= M;i++) {
			P[i] = sc.nextInt();
			X[i] = sc.nextInt();
		}

		for (int i = 1;i <= M;i++) {
			System.out.println(sum - T[P[i]] + X[i]);
		}
	}
}

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

int n;
string s;

int main() {

    cin >> n >> s;

    char first,second;

    char my_set[4][2] = {{'S','S'},{'W','S'},{'S','W'},{'W','W'}};

    for(int loop=0; loop<4; loop++){

        string ans = "";

        first = my_set[loop][0];
        second = my_set[loop][1];

        ans.push_back(first);
        ans.push_back(second);

        for(int i=1; i<s.size(); i++){

            if(second == 'S') {

                if (s[i] == 'o') {
                    ans.push_back(first);
                    second = first;
                    first = 'S';
                } else {//x
                    if (first == 'S') {
                        ans.push_back('W');
                        first = second;
                        second = 'W';
                    } else {
                        ans.push_back('S');
                        first = second;
                        second = 'S';
                    }
                }
            }
            else{
                if (s[i] == 'x') {
                    ans.push_back(first);
                    second = first;
                    first = 'W';
                } else {//o
                    if (first == 'S') {
                        ans.push_back('W');
                        first = second;
                        second = 'W';
                    } else {
                        ans.push_back('S');
                        first = second;
                        second = 'S';
                    }
                }
            }

        }

        if(ans[ans.size()-1] != ans[0]){
            continue;
        }

        ans.erase(ans.end()-1);

        if(my_set[loop][0] == 'S') {

            if (s[0] == 'o' && first == my_set[loop][1]) {
                cout << ans << endl;
                return 0;
            } else if (s[0] == 'x' && first != my_set[loop][1]) {
                cout << ans << endl;
                return 0;
            }
        }
        else{
            if (s[0] == 'x' && first == my_set[loop][1]) {
                cout << ans << endl;
                return 0;
            } else if (s[0] == 'o' && first != my_set[loop][1]) {
                cout << ans << endl;
                return 0;
            }
        }

    }

    cout << -1 << endl;

    return 0;
}

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

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

signed main() {
	int n, m; cin >> n >> m; vector<int>a(n + 1);
	rep(i, 1, n + 1)cin >> a[i];
	for (int k = 1; k <= m; k++) {
		int b = 1;
		while (1) {
			if (b != n) {
				if (a[b] % k > a[b + 1] % k)swap(a[b], a[b + 1]);
				b++;
			}
			else break;
		}
	}
	rep(i, 1, n + 1)cout << a[i] << endl;
	return 0;
}

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

using namespace std;

#define ll long long

int
main(void){
	int n, t; cin >> n >> t;
	ll ans = 0;
	vector<int> vec(n);
	for(int i = 0; i < n; i++) cin >> vec[i];
	int l = 0;
	for(int i = 1; i < n; i++){
		if(l + t <= vec[i]) ans += t;
		else ans += (vec[i] - l);
		l = vec[i];
	}
	ans += t;
	cout << ans;
}

Measured memory_bytes: 1024
// atcoder/abc153/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "("; each (i, s) os << i << ","; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "("; each (i, m) os << i << ","; os << ")"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> swap(pair<P, Q> p) { return make_pair(p.second, p.first); }

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int h, a;
  while (cin >> h >> a) {
    cout << (h / a) + bool(h % a) << endl;
  }

  return 0;
}


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

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int n,d,a;
  cin>>n>>d>>a;
  P memo[n];
  for(int i=0;i<n;i++){
    int x,h;
    cin>>x>>h;
    h=(h+a-1)/a;
    memo[i]=make_pair(x,h);
  }
  sort(memo,memo+n);
  ll ans=0;
  queue<llP> que;
  ll x,h,tmp=0,cnt=0;
  for(int i=0;i<n;i++){
    x=memo[i].first;
    while(!que.empty()){
      if(que.front().first<x){
        tmp-=que.front().second;
        que.pop();
      }
      else break;
    }
    h=memo[i].second-tmp;
    if(h<=0) cnt=0;
    else cnt=h;
    que.push(make_pair(x+2*d,cnt));
    tmp+=cnt;
    ans+=cnt;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5120
# -*- coding: utf-8 -*-
import sys
from math import floor
sys.setrecursionlimit(100000)

N = int(input())
A = [None] + [int(n) for n in input().split()]

def max_heapify(A, i):
    l = 2 * i
    r = 2 * i + 1
    if l <= N and A[l] > A[i]:
        largest = l
    else:
        largest = i
    
    if r <= N and A[r] > A[largest]:
        largest = r
    
    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        max_heapify(A, largest)

for i in range(N//2, 0, -1):
    max_heapify(A, i)

print(" " + " ".join(map(str, A[1:])))

Measured memory_bytes: 66624
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

bool isOk(int key,int value){
  return value >= key;
}

int binary_search(vector<int> a,int key){
  int ok = a.size();
  int ng = -1;

  while(abs(ok - ng) > 1){
    int mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  char s[1000];cin>>s;

  int size = strlen(s);
  for(int i = size-2;i;i -= 2){
    if(strncmp(s,s+i/2,i/2) == 0){
      print(i);return 0;
    }
  }
  print(0);
  return 0;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nmax 100000
int main(){
  int n,ans=0,tmp,cnt=1;
  int a[nmax];
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  tmp=a[0];
  for(int i=1;i<n;i++){
    if(a[i]==tmp) cnt++;
    else{
      if(cnt%2) ans++;
      cnt=1;
      tmp=a[i];
    }
  }
  if(cnt%2) ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))

s = 0
for i in range(N):
    for j in range(i + 1, N):        
        k = bisect.bisect_left(L, L[i] + L[j])
        s += k - j - 1

print(s)

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

typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define mp make_pair

int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", max(a+b, max(a-b, a*b)));
    return 0;
}


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

int main(){
	int a,b,ans;
	char op;

	while(1){
		cin>>a>>op>>b;
		switch(op){
			case '+': ans=a+b; break;
			case '-': ans=a-b; break;
			case '*': ans=a*b; break;
			case '/': ans=a/b; break;
			case '?': return 0;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

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


	if (n == 1) {
		if (m == 1) {
			cout << 1 << endl;
		}
		else {
			cout << m - 2 << endl;
		}
	}
	else {
		if (m == 1) {
			cout << n - 2 << endl;
		}
		else {
			cout << (n - 2)*(m - 2) << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
b = [1]*(n + 1)

for i in a:
    b[i] = 0

for i in range(2, n + 1):
    if b[i] != 0:
        b[i] = b[i - 2] + b[i - 1]

print(b[-1]%(10**9 + 7))

Measured memory_bytes: 460020