akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    String lineOriginal = sc.next();
    String[] alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    int max = 0;
    for (int i = 1; i < number; i++) {
      String line1 = lineOriginal.substring(0, i);
      String line2 = lineOriginal.substring(i, number);
      int count = 0;
      for (int j = 0; j < 26; j++) {
        if (line1.contains(alphabet[j]) && line2.contains(alphabet[j])) {
          count++;
        }
      }
      if (count > max) {
        max = count;
      }
     

      
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 23124
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
using ll = long long;

template<typename T>
struct sparse_table {
    vector<vector<T>> st;

    sparse_table(const vector<T>& a) {
        const int w = lg(a.size());
        st.reserve(w);
        st.emplace_back(a);
        for (int k = 1; k < w; k++) {
            st.emplace_back(vector<T>(a.size() - (1 << k) + 1));
            for (int i = 0; i < (int) a.size() - (1 << k) + 1; i++)
                st[k][i] = max(st[k - 1][i], st[k - 1][i + (1 << (k - 1))]);
        }
    }

    inline int lg(T n) {
        return 64 - __builtin_clzll(n);
    }

    inline T query(int l, int r) {
        if (l > r) return 0;
        int k = lg(r - l + 1) - 1;
        return max(st[k][l], st[k][r - (1 << k) + 1]);
    }
};

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
    //    freopen("out", "w", stdout);
#endif
    //    ios::sync_with_stdio(0), cin.tie(0);
    ll n, c;
    scanf("%lld%lld", &n, &c);
    vector<ll> x(n), v(n), F(n), B(n);
    for (int i = 0; i < n; i++) {
        scanf("%lld%lld", &x[i], &v[i]);
    }

    F[0] = v[0];
    for (int i = 1; i < n; i++)
        F[i] = F[i - 1] + v[i];
    for (int i = 0; i < n; i++)
        F[i] -= x[i];

    B[0] = v[n - 1];
    for (int i = 1; i < n; i++)
        B[i] = B[i - 1] + v[n - i - 1];
    for (int i = 0; i < n; i++)
        B[i] -= (c - x[n - i - 1]);

    sparse_table<ll> fst(F), bst(B);

    ll ans = LLONG_MIN;
    for (int i = 0; i < n; i++) {
        ll cur = max(F[i], F[i] + bst.query(0, n - 2 - i) - x[i]);
        ans = max(ans, cur);
    }

    ll res = LLONG_MIN;
    for (int i = 0; i < n; i++) {
        ll cur = max(B[i], B[i] + fst.query(0, n - 2 - i) - (c - x[n - i - 1]));
        res = max(res, cur);
    }

    cout << max({0LL, res, ans}) << endl;

    return 0;
}


Measured memory_bytes: 28032
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var K = cin.ReadInt;
            var X = cin.ReadInt;

            if (K * 500 >= X)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
         


            
    


        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 27820
fn main() {
    let mut sc = Scanner::new();
    let a = sc.usize_read();
    let b = sc.usize_read();
    if a <= 8 && b <= 8 {
        println!("Yay!");
    } else {
        println!(":(");
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
//#include<ext/rope>
//using namespace __gnu_cxx
//#include<ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;
#define lowbit(x) (x&-x)
#define pb push_back
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define clr(a,b) memset(a,b,sizeof(a))
#define caze(T) for(cin>>T;T;T--)
#define inf (1<<29)
#define Endl ('\n')
#define fi first
#define se second
#define db double
#define ldb long double
#define ll long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
inline char nc() {
	#define SZ 1000000
	static char buf[SZ], *p1, *p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline int scan(T &x) {
	char c, sign=1; 
	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;
	if(c==EOF) return EOF;
	for(x = 0; isdigit(c); c = nc())
		x = (x<<1) + (x<<3) + (c&15);
	return x *= sign, 1;
}
template<typename T, typename...Args>
inline int scan(T &x, Args&...args) {
	return scan(x), scan(args...);
}
int main()
{
	int n;cin>>n;
	cout<<n*(1+(n&1))<<Endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vecint st;
  REP(i,n) {
    int a;
    cin>>a;
    if (st.size() >= 2) {
      int k = st.size();
      if (st[k-2] <= st[k-1] && st[k-1] <= a) {
        st.pop_back();
      } else if (st[k-2] >= st[k-1] && st[k-1] >= a) {
        st.pop_back();
      }
    }
    st.push_back(a);
  }
  int k = st.size();
  ll money = 1000;
  ll stock = 0;
  REP(i,k-1) {
    if (st[i] > st[i+1]) {
      money += stock * st[i];
      stock = 0;
    } else {
      stock += money / st[i];
      money %= st[i];
    }
  }
  money += stock * st.back();
  cout<<money<<endl;
  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t x;
    cin >> x;
    vector<int64_t> v;
    for(int i=1; i<40; i++){
        int64_t tmp = i;
        for(int j=0; j<10; j++){
            tmp*=i;
            if(tmp>1000) break;
            v.push_back(tmp);
        }
    }
    sort(v.begin(), v.end());
    int64_t res = 1;
    for(int i=0; i<v.size(); i++){
        if(v.at(i)>x){
            break;
        }
        res = v.at(i);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
using System;

namespace practise
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 1;
            int j = 1;
            while(true) {
                int ans = i * j;
                Console.WriteLine("{0}x{1}={2}", i, j, ans);
                j++;
                if (j > 9)
                {
                    i++; 
                    j = 1;
                }
                if (i > 9)
                {
                    break;
                } 
            }
        }
    }
}

Measured memory_bytes: 8992
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vpll vector<pair<ll,ll>>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define fi first
#define se second
#define pb push_back
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mib map<int,bool>
#define mlb map<ll,bool>
#define f(i,k,n) for(ll i=k;i<n;i++)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll mod=1e9+7;
const ld pii=3.141592653589793238;
int main()
{
    IOS
    ld r;
    cin>>r;
    ld ans=2*pii*r;
    cout<<ans<<endl;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define int long long
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;
//cout<<fixed<<setprecision(15);

signed main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    int lc=lcm(c,d);
    int divc=b/c-(a-1)/c;
    int divd=b/d-(a-1)/d;
    int divcd=b/lc-(a-1)/lc;
    //cout<<divc<<' '<<divd<<' '<<divcd<<endl;
    cout<<(b-a+1)-divc-divd+divcd<<endl;
}

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

int main(void)
{
	int N;
	int n=0, k, i;

	cin >> N;
	for (i = 1; i <= N; i++) {
		cin >> k;
		if (i != k)n++;
	}
	if (n <= 2)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

using namespace std;

int main () {
	int N, D, c = 0;
	cin >> N >> D;
	vector<vector<int>> S(N);
	for (int i = 0; i < N; i++) {
		S[i].resize(D);
		for (int j = 0; j < D; j++) {
			cin >> S[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i; j++) {
			int m = 0;
			for (int k = 0; k < D; k++) {
				int e = S[i][k] - S[j][k];
				m += (e * e);
			}
			int r = floor(sqrt((double)m));
			if (r * r == m) {
				c++;
			}
		}
	}
	cout << c << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  int count = 0;
  int outlet_sum = 1;
  while (outlet_sum < b) {
    outlet_sum += a-1;
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
using lint = long long;
lint N, arr[200'000];
lint calc(int b) {
    lint ret = 0;
    for(int i = 0; i < N; i++) {
        ret += abs(arr[i] - b - 1 - i);
    }
    return ret;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>N;
    for(int n = 0; n < N; n++) cin>>arr[n];
    lint bot = -1e9, top = 1e9;
    while(bot < top-2) {
        lint l = bot + (top-bot)/3, r = bot + (top-bot)*2/3;
//        cout<<bot<<' '<<l<<' '<<r<<' '<<top<<'\n';
        if(calc(l) < calc(r)) {
            top = r;
        }
        else {
            bot = l;
        }
    }
    cout<<min({calc(bot), calc(bot+1), calc(top)})<<'\n';
    return 0;
}

Measured memory_bytes: 1792
from bisect import bisect_right


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

baseCnt = [0] * N
for idx, b in enumerate(B):
    ci = bisect_right(C, b)
    baseCnt[idx] = N - ci

S = [0] * (N + 1)
for i in range(N):
    S[i + 1] = S[i] + baseCnt[i]

ans = 0
for a in A:
    bi = bisect_right(B, a)
    ans += S[N] - S[bi]

print(ans)


Measured memory_bytes: 24812
N = int(input())
H = list(map(int, input().split()))

prev = H[0]
ans, cnt = 0, 0
for cur in H[1:]:
    if cur <= prev:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0
    prev = cur
ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 15020
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
using P = pair<int,int>;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)

int main(){
    const int MAX = 1000000;
    vector<int> tetra,tetra_odd;
    vector<int> ans(MAX+1,MAX), ans_odd(MAX+1,MAX);
    ans[0] = 0;
    ans_odd[0] = 0;

    int n=1;
    while(n*(n+1)*(n+2) / 6 <= MAX){
        int k = n*(n+1)*(n+2) / 6;
        tetra.emplace_back(k);
        if(k&1) tetra_odd.emplace_back(k);
        n++;
    }

    for(int i=0;i<=MAX;i++){
        for(int j=0;j<tetra.size();j++){
            if(i-tetra[j] < 0) continue;
            ans[i] = min(ans[i],ans[i-tetra[j]]+1);
        }
    }

    for(int i=0;i<=MAX;i++){
        for(int j=0;j<tetra_odd.size();j++){
            if(i-tetra_odd[j] < 0) continue;
            ans_odd[i] = min(ans_odd[i],ans_odd[i-tetra_odd[j]]+1);
        }
    }

    int N;
    while(cin >> N, N != 0){
        cout << ans[N] << " " << ans_odd[N] << endl;
    }
}


Measured memory_bytes: 10556
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];
    int ans=0;
    rep(i,n-2){
        for(int j=i+1; j<n-1; ++j){
            for(int k=j+1; k<n; ++k){
                if(p[i]!=p[j] && p[j]!=p[k] && p[k]!=p[i]){
                    ll m=max(p[i], max(p[j],p[k]));
                    if((p[i]+p[j]+p[k])>2*m) ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
import sys
def input():
    return sys.stdin.readline()[:-1]

N,K = map(int,input().split(' '))
r,s,p = map(int,input().split(' '))
S = list(input())
ANS = [None]*N

ans = 0
for i in range(K):
    k = S[i]
    if 'r' == k:
        ans += p
        ANS[i] = 'p'
    elif 's' == k:
        ans += r
        ANS[i] = 'r'
    else:
        ans += s
        ANS[i] = 's'

for j in range(K,N):
    k = S[j]
    pre = ANS[j-K]
    if 'r' == k:
        if pre=='p':
            ANS[j] = 0
        else:
            ans += p
            ANS[j] = 'p'
    elif 's' == k:
        if pre=='r':
            ANS[j] = 0
        else:
            ans += r
            ANS[j] = 'r'
    else:
        if pre=='s':
            ANS[j] = 0
        else:
            ans += s
            ANS[j] = 's'
print(ans)

Measured memory_bytes: 4792
use proconio::input;
use proconio::marker::Chars;
use std::collections::HashSet;
use std::iter::Iterator;

fn main() {
    input! {
        k: i32,
        a: i32,
        b: i32,
    }

    let mut ans = false;
    for i in a..=b {
        if i % k ==  0 {
            ans = true;
        }
    }

    if ans {
        println!("OK");
    }else{
        println!("NG");
    }

}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    vector <int> v(s.length());
    for(int i = 0; i < v.size(); i++){
        v[i]=s[i]-'A';
        v[i]+=n;
        v[i]%=26;
        cout << (char)(v[i]+'A');
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(){
    int count = 0;
    string ans;
    string line;
    getline(cin, line);
    int size = line.size();

    for (int i = 0; i<size;i++) {
        if(line[i] == 'o') count++;
    }
    count += (15-size);

    if(count >= 8) ans = "YES";
    else ans = "NO";
    cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int x = sc.nextInt();
     	for(int i=x;i<x+100002;i++){
         if(isprime(i)){
            System.out.println(i);
           	break;
        }
    }
 }public static boolean isprime(int num){
      boolean isp = true;
      for(int i=2;i<=Math.sqrt(num);i++){
        if (num%i == 0){
        isp = false;
        }
      }
      return isp;
    }
}

Measured memory_bytes: 27032
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int p[11];

int main(void){
    scanf("%d",&n);
    int sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&p[i]);
        sum+=p[i];
    }
    sort(p,p+n);
    sum-=p[n-1]/2;
    printf("%d\n",sum);
    return 0;
}

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

int main() {
  int N,sum=0; cin >> N;
  vector<vector<int>> data(2,vector<int>(N));

  for(int i=0; i<2; i++) {
    for(int j=0; j<N; j++) {
      cin >> data.at(i).at(j);
    }
  }
  for(int i=0; i<N; i++) {
  if(data.at(0).at(i)>data.at(1).at(i)) {
      sum += data.at(0).at(i)-data.at(1).at(i);
  }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3628
from itertools import combinations

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

MAX=(N-1)*(N-2)//2

if K>MAX:
  print(-1)
  exit()

n_add=MAX-K
M=N-1+n_add
e_comb = list(combinations(range(2,N+1),r=2))

print(M)
for i in range(M):
  if i < N-1:
    print(*(1,2+i))
  else:
    print(*e_comb[i-(N-1)])

Measured memory_bytes: 9396
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define ull unsigned long long
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define FOR(i,start,stop)  for(int i=(start); i < (stop); i++)
#define FORD(i,start,stop) for(int i=(start); i >= (stop); i--)
#define RIP(i,stop) FOR(i,0,stop)
#define PI 3.141592653589793
#define PRECISION(c,f) fixed << setprecision(c) << f
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,m; 
  cin >> n >> m;

  int ans = n * (n-1) / 2+m*(m-1) / 2;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a%b==0) co(0);
  else co(1);
  return 0;
}


Measured memory_bytes: 256
import sys
import fractions
input = sys.stdin.readline


def gcd(x, y):
    while y > 0:
        r = x%y
        x = y
        y = r
    return x
 
def lcm(x, y):
    return x//fractions.gcd(x, y)*y
 
n = int(input())
a = list(map(int, input().split()))
 
l = 1
for x in a:
    l = lcm(x, l)
 
ans = 0
for x in a:
    ans += l//x
 
print(ans%(10**9+7))


Measured memory_bytes: 6112
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#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 <cstdint> // int64_t, int*_t
#include <limits>//setprecision
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
//int MOD = 1000000007;
typedef pair<long long,long long> P;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M,long long MOD) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2,MOD);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

vector<vector<int>> Edge(100005);
vector<int> ans(100005);
vector<int> indegree(100005);
queue<pair<int,int>> non_indegree;

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N,M;cin >> N >> M;
    for(int i = 0;i<N+M-1;i++){
        int from,to;cin >> from >> to;
        Edge.at(from).push_back(to);
        indegree.at(to)++;
    }
    for(int i = 0;i<N;i++) if(indegree.at(i) == 0) non_indegree.push(make_pair(i,0));
    while(!non_indegree.empty()){
        int from = non_indegree.front().first,parent = non_indegree.front().second;
        non_indegree.pop();
        //木が一意に定まるので同時に2頂点以上の入次数が0になることはない
        ans.at(from) = parent;
        for(int to : Edge.at(from)){
            indegree.at(to)--;
            if(indegree.at(to) == 0){
                non_indegree.push(make_pair(to,from));
            }
        }
    }
    for(int i = 1;i<=N;i++) cout << ans.at(i) << endl;
}


Measured memory_bytes: 9504
X=input()
Y=input()
Z=input()
A=list(X[i] for i in range(len(X)))
B=list(Y[i] for i in range(len(Y)))
C=list(Z[i] for i in range(len(Z)))
#print(A,B,C)
K=A
ans=""
while True:
    
    if K == []:
        print(ans)
        
        exit()
    elif K[0]=="a":
        K.pop(0)
        K=A
        ans="A"
    elif K[0]=="b":
        K.pop(0)
        K=B
        ans="B"
    else:
        K.pop(0)
        K=C
        ans="C"

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<int> a, b;
  Solver(LL n) : n(n), a(n), b(n - 1){};

  void solve() {
    int m = n - 2;
    for (int i = 0; i < n; ++i) {
      char c;
      cin >> c;
      a[i] = c - '0';
    }
    for (int i = 0; i < n - 1; ++i) {
      b[i] = abs(a[i] - a[i + 1]);
    }
    DBG(b)
    bool even = true;
    for (int i = 0; i < n - 1; ++i) {
      if (b[i] == 1) even = false;
    }
    if (even) {
      for (int i = 0; i < n - 1; ++i) {
        b[i] /= 2;
      }
    } else {
      for (int i = 0; i < n - 1; ++i) {
        b[i] %= 2;
      }
    }
    DBG(even, b)
    int ans = 0;
    int now = 0;
    for (int i = 0; i < n - 1; ++i) {
      if (i == 0) {
        int d = (now == 0);
        int tmp = b[i] & d;
        ans ^= tmp;
      } else {
        int num = m - i + 1;
        int den = i;
        now += cnt(num) - cnt(den);
        int d = (now == 0);
        int tmp = b[i] & d;
        ans ^= tmp;
      }
    }
    DBG(ans)
    cout << ans * (even ? 2 : 1) << endl;
  }
  int cnt(int x) {
    int ret = 0;
    while (x % 2 == 0) {
      ret++;
      x /= 2;
    }
    return ret;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
int A[100010];

int main () {
  cin >> N;
  for (auto i = 0; i < N; ++i) {
    cin >> A[i];
  }
  bool force_inc = false;
  bool force_dec = false;
  int cnt = 1;
  for (auto i = 0; i < N-1; ++i) {
    int now = A[i];
    int next = A[i+1];
    if ((force_inc && now > next) || (force_dec && now < next)) {
      cnt++;
      force_inc = false;
      force_dec = false;
    } else if (now < next) {
      force_inc = true;
    } else if (now > next) {
      force_dec = true;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
    cin>>N>>M;
  for(int i=0;i<M;i++){
    int A;
    cin>>A;
    N-=A;
    if(N<0){
      cout<<-1<<endl;
      break;
    }
  }
  if(N>-1){
    cout<<N<<endl;
  }
  
 
}

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

#define MAXN 100000

typedef long long ll;

using namespace std;

ll A[MAXN];

bool comlarge ( const ll x, const ll y ) { return x > y; }

ll find ( int N )
{
  ll f,s,cnt,i;

  cnt = 0;
  f = A[0];
  for ( i = 0; i < N; ++i  ) {
    if ( f == A[i] ) {
      ++cnt;
      if ( cnt >= 2 ) break;
    } else {
      cnt = 1;
      f = A[i];
    }
  }

  s = A[++i];
  cnt = 0;
  for ( ; i < N; ++i ) {
    if ( s == A[i] ) {
      ++cnt;
      if ( cnt >= 2 ) {
        return f*s;
      }
    } else {
      cnt = 1;
      s = A[i];
    }
  }

  return 0;
}


int main()
{
  int N;

  cin >> N;

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

  cout << find(N) <<"\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < ((int)(b)); ++i)
#define rrep(i, a, b) for (int i = ((int)(b)) - 1; i >= (a); --i)
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi = vector<int>;
constexpr int INF = 1001001001001001001LL;

void dump_impl(string s) {}
template <class H, class... T>
void dump_impl(string s, const H &head, const T&... tail) {
    int par = 0;
    rep(i, 0, sz(s)) {
        char ch = s[i];
        if (ch == ',' && par == 0) {
            cerr << " = " << head << ", ";
            dump_impl(s.substr(i + 1), tail...);
            return;
        } else {
            cerr << ch;
            if (ch == '(') par++;
            if (ch == ')') par--;
        }
    }
}
#define dump(...) do { cerr << "\x1b[33;1m"; dump_impl(#__VA_ARGS__ ",", __VA_ARGS__); cerr << "\x1b[0m" << endl; } while (0)

struct SCC {
    vvi &g;
    vvi dag;
    vi comp;

    SCC(vvi &g) : g(g) {}

    // 強連結成分の番号をcompに格納、個数を返す
    int compute() {
        int n = sz(g);
        comp.assign(n, -1);
        
        vvi rg(n);
        rep(v, 0, n) for (int w : g[v]) rg[w].push_back(v);

        vi vs;
        vector<bool> vis(n, false);
        auto dfs = [&](auto f, vvi &G, int v, auto for_each_node) -> void {
            vis[v] = true;
            for (int w : G[v]) if (!vis[w]) f(f, G, w, for_each_node);
            for_each_node(v);
        };

        rep(v, 0, n) {
            if (!vis[v]) {
                dfs(dfs, g, v, [&](int w) { vs.push_back(w); });
            }
        }
        fill(all(vis), false);

        int cnt = 0;
        rrep(i, 0, sz(vs)) {
            if (!vis[vs[i]]) {
                dfs(dfs, rg, vs[i], [&](int w) { comp[w] = cnt; });
                cnt++;
            }
        }
        return cnt;
    }

    void build_dag() {
        int n = sz(g);
        int size = compute();
        dag = vvi(size);
        vector<set<int>> se(size);
        rep(v, 0, n) se[comp[v]].insert(v);
        rep(i, 0, size) {
            set<int> out;
            for (int v : se[i]) {
                for (int w : g[v]) {
                    out.insert(comp[w]);
                }
            }
            for (int x : out) {
                dag[i].push_back(x);
            }
        }
    }
};

signed main() {
    int V, E;
    cin >> V >> E;
    vvi g(V);
    rep(i, 0, E) {
        int vs, vt;
        cin >> vs >> vt;
        g[vs].push_back(vt);
    }
    SCC scc(g);
    scc.compute();
    scc.compute();

    int Q;
    cin >> Q;
    while (Q--) {
        int vs, vt;
        cin >> vs >> vt;
        if (scc.comp[vs] == scc.comp[vt]) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 4660
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner inputs = new Scanner(System.in);
		int N = inputs.nextInt();
		int M = inputs.nextInt();
		int sum = 0;
		if(N>=2) {
			sum+=comb(N,2);
		}
		if(M>=2) {
			sum+=comb(M,2);
		}
		System.out.println(sum);
	}
	static int comb(int n , int r)
	{
		if( r== 0 || n == r)
			return 1;
		else
			return comb(n-1,r)+comb(n-1,r-1);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 505, MAXP = 10005;
int vis[MAXP], p[MAXN], q[MAXN], n = 500;
LL mp[MAXN][MAXN];
void judge(LL x, LL y) {
	if (x < y) swap(x, y);
	assert(x % y == 1);
}

int main() {
	int R = 0, C = n;
	for (int i = 2; i < MAXP; i++) if (!vis[i]) {
		if (R < n) p[R + 1] = p[R + 2] = i, R += 2;
		else if (C > 0) q[C] = q[C - 1] = i, C -= 2;
		for (int j = i + i; j < MAXP; j += i) vis[j] = 1;
	}
	p[0] = q[0] = p[n + 1] = q[n + 1] = 1;
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= n; j++) {
		LL cur = 0;
		if ((i + j) & 1) {
			cur = p[i] * q[j];
			if (~i & 1) cur <<= 1;
		} else {
			cur = (LL)p[i - 1] * p[i + 1] * q[j - 1] * q[j + 1] * 2;
			if (i & 1) cur <<= 1;
			++cur;
		}
		mp[i][j] = cur;
		assert(cur <= 1e15);
		if (i > 1) judge(mp[i][j], mp[i - 1][j]);
		if (j > 1) judge(mp[i][j], mp[i][j - 1]);
	}
	scanf("%d", &n);
	for (int i = 1; i <= n; i++, puts(""))
	for (int j = 1; j <= n; j++) printf("%lld ", mp[i][j]);
	return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int d=i;
		int u=0;
		while(d>0)
		{
			u++;
			d/=10;
		}
		if(u%2!=0)
		{
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int a, b, c;
    cin >> a >> b >>c;
    if(a-c == 0){
        cout << b << endl;
        return 0;
    }
    if(b-c == 0){
        cout << a << endl;
        return 0;
    }
    if(a-b == 0){
        cout << c << endl;
        return 0;
    }
}

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

int main(){
  string s;
  cin >> s;
  int index_start = 20000000, index_end = 0;
  for(int i = 0; i < s.size(); i++){
    if( s[i] == 'A' && index_start > i ) index_start = i;
    else if ( s[i] == 'Z' && index_end < i ) index_end = i;
  }
  int ans = index_end - index_start + 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
ll dp[3][3333][3333];
ll n,m,k;
ll v[3333][3333];
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n>>m>>k;
	rep(i,k)
	{
		ll a,b,c;
		cin>>a>>b>>c;
		v[a-1][b-1]=c;
	}
	memset(dp,0,sizeof(dp));
	rep(i,n)
	{
		rep(j,m)
		{
			dp[0][i][j]=max(dp[0][i][j],v[i][j]);
			if(i>0)
			{
				dp[0][i][j]+=max(dp[0][i-1][j],max(dp[1][i-1][j],dp[2][i-1][j]));	
			}
			if(j>0)
			{
				dp[0][i][j]=max(dp[0][i][j],dp[0][i][j-1]); 
				dp[1][i][j]=max(dp[1][i][j-1],dp[0][i][j-1]+v[i][j]);
				dp[2][i][j]=max(dp[2][i][j-1],dp[1][i][j-1]+v[i][j]); 
			}
		}
	}
	cout<<max(dp[2][n-1][m-1],max(dp[1][n-1][m-1],dp[0][n-1][m-1]))<<endl;
	return 0;
}
 

Measured memory_bytes: 341848
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

vector <vi> adj;
vi dp;
int n, k;

void input()
{
	int x, y;
	cin >> n >> k;
	adj.resize(n + 1);
	dp.resize(n + 1, 1);
	
	for (int i = 1; i < n; i++)
	{
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
}

void dfs (int cur = 1, int prev = 0)
{
	int x = k - 2;
	for (int i: adj[cur])
		if (i != prev)
		{
			dfs(i, cur);
			dp[cur] = dp[cur] * dp[i] % mod * x % mod;
			x--;
		}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
	input();
	dfs();
	
	int ans = k, x = k - 1;
	for (int i: adj[1])
	{
		ans = ans * dp[i] % mod * x % mod;
		x--;
	}
	cout << ans;
}

Measured memory_bytes: 12416
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n,k;cin>>n>>k,n|k;){
		vi flg(n+1);
		rep(i,k){
			int x; cin>>x;
			flg[x]++;
		}
		vvi dp(2,vi(n+1));
		repi(i,1,n+1){
			if(flg[i]){
				dp[0][i]=dp[0][i-1]+1;
				dp[1][i]=dp[1][i-1]+1;
			}
			else{
				dp[0][i]=0;
				dp[1][i]=dp[0][i-1]+1;
			}
		}
		cout<<*max_element(allof(dp[flg[0]]))<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)

using namespace std;

int main() {
    int a;
    vector<int> b;
    while(true) {
        cin >> a;
        if(a != 0) b.push_back(a);
        else break;
    }
    rep(i,(int)b.size()) cout << "Case " << i+1 << ": " << b[i] << endl;
}


Measured memory_bytes: 3104
def bubble(n, a):
    count = 0
    for i in range(n-1):
        for j in range(n-1,i,-1):
            if a[j-1] > a[j]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                count += 1
    return count, a
    
n = int(raw_input())
a = map(int, raw_input().split())

n, a = bubble(n, a)
print " ".join(map(str, a))
print n

Measured memory_bytes: 4228
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int n;
    cin >> n;
    int p;
    int min = n;
    int num = 0;
    for(int i=0;i<n;i++){
        cin >> p;
        if(p<=min){
            min = p;
            num++;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;

public class Kadai
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        string inp_str = Console.ReadLine();
        string[] inp_arr = inp_str.Split(' ');
        int[] input = new int[n];
        for (int i = 0; i < n; i++)
        {
            input[i] = int.Parse(inp_arr[i]);
        }
        int count = 0;

        bool flag = true;
        while (flag)
        {
            flag = false;
            for (int j = n - 1; j > 0; j--)
            {
                if (input[j] < input[j - 1])
                {
                    int temp = input[j];
                    input[j] = input[j - 1];
                    input[j - 1] = temp;
                    flag = true;
                    count++;
                }
            }
        }

        for (int k = 0; k < n - 1; k++)
        {
            Console.Write(input[k]);
            Console.Write(' ');
        }
        Console.WriteLine(input[n - 1]);
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 17912
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int i,idx,k,cnt=0,n;
    map<int,int>a;
    cin>>n;
    idx=0;
    for(i=0;i<n;i++){cin>>k;a[k]++;}
    map<int,int>::iterator it;
    for(it=a.begin();it!=a.end();it++){
     if((it->second)%2==1){cnt++;}
    }
    cout<<cnt<<endl;
     


}

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

using namespace std;
const int N = 101;
const int W = 1e5+1;

#define fr first
#define sc second
#define int long long
#define pii pair < int, int >

int dp[W][N];
vector < pii > v;

main() {
	int n, w;
	cin >> n >> w;
	
	int sum = 0;
	for(int i = 1; i <= n; i++) {
	  int wi, vi; cin >> wi >> vi;
		v.push_back( { wi, vi } );
		sum += vi;
	}
	
	for(int i = 1; i <= sum; i++) {
		for(int j = 0; j <= n; j++) {
			dp[i][j] = 1e9;
		}
	}

	for(int i = 1; i <= sum; i++) {
		for(int j = 1; j <= n; j++) {
			dp[i][j] = dp[i][j - 1]; int cs;
			cs = v[j - 1].sc; if(cs > i) continue;

			long long we = v[j - 1].fr;
			if(dp[i][j] > dp[i - cs][j - 1] + we) {
				dp[i][j] = dp[i - cs][j - 1] + we;
			}
		}
	}

	for(int i = sum; i >= 0; i--) {
		if(dp[i][n] <= w) return cout << i, 0;
	}

	cout << 0 << endl;
}

Measured memory_bytes: 79104
#include<stdio.h>
char *P[]={"No","Yes"};
char f;

int n, m;
char s[11], c, i;
int main(){
  scanf("%s", s);
  while(c=s[i++]){
    n=n*10+c-'0';
    m=m+c-'0';
  }
  f = (n%m)==0;
  puts(P[f]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if ((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3588
// Author: Shusuke Ueda
// AtCoder Beginner Contest 136 - Problem E

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int n, k;
    std::cin >> n >> k;

    std::vector<int> a(n);
    int sum = 0;
    for (auto& e: a) {
        std::cin >> e;
        sum += e;
    }

    auto check = [=](int i) -> bool {
        auto b = a;
        for (auto& e : b) {
            e %= i;
        }
        std::sort(b.begin(), b.end());

        int cnt = 0;
        int left = 0, right = n - 1;
        while (left < right) {
            if (b[left] == 0) {
                left++;
            } else if (b[right] == 0 or b[right] == i) {
                right--;
            } else {
                int tmp = std::min(b[left], i - b[right]);
                cnt += tmp;
                b[left] -= tmp;
                b[right] += tmp;
                if (cnt > k) {
                    return false;
                }
            }
        }
        return true;
    };
    int ans = 1;
    for (int i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            if (check(i)) {
                ans = std::max(ans, i);
            };
            if (i != sum / i) {
                if (check(sum / i)) {
                    ans = std::max(ans, sum / i);
                };
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

// order statistics tree
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> indexed_set;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define rrep(i, b, a) for(int i = b; i >= a; --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

const int N = 1001;
const int INF = 1e9;
const int X = 5001;
int n;
int parent[N];
vector<int> children[N];
int weight[N];
int other_weight[N];

bool possible;

void postorder(int v){
  if(!possible) return;

  int nc = sz(children[v]);

  // traverse children first
  rep(i, 1, nc){
    postorder(children[v][i]);
  }

  int hi = weight[v];

  // [# children used][weight of white] = is possible?
  bool dp[nc][hi+1];

  memset(dp, false, sizeof(dp));

  dp[0][0] = true;

  int total = 0;
  rep(i, 1, nc){
    int c = children[v][i];
    int wc = weight[c], owc = other_weight[c];

    total += wc + owc;

    rep(w, 0, hi+1){
      if(!dp[i-1][w]) continue;

      if(w + wc <= hi) dp[i][w+wc] = true;
      if(w + owc <= hi) dp[i][w+owc] = true;
    }
  }

  int ans = -1;
  rrep(w, hi, 0){
    if(dp[nc-1][w]){
      ans = total - w;
      break;
      // printf("ans: %d\n", ans);
    }
  }

  if(ans == -1){
    possible = false;
  } else {
    other_weight[v] = ans;
  }
}

int main() {
  cin.tie(0); cin.exceptions(cin.failbit);

  scanf("%d", &n);

  // all a null child to the beginning of each vector
  rep(i, 1, n+1){
    children[i].PB(0);
  }

  rep(i, 2, n+1){
    scanf("%d", parent+i);
    children[parent[i]].PB(i);
  }
  rep(i, 1, n+1) scanf("%d", weight+i);

  possible = true;

  postorder(1);

  printf("%s\n", possible ? "POSSIBLE" : "IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define DEBUG if(0)
#define pb push_back
#define pf push_front
#define mp make_pair
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int arr[n];
    int aux[n];
    for(int i = 0; i < n; i++) {
    	cin >> arr[i];
    	aux[i] == arr[i];
    }
    for(int i = 0; i < n; i++) aux[arr[i] - 1] = i + 1;
   	for(int i = 0; i < n; i++) printf("%d%c", aux[i], (i < n - 1) ? ' ' : '\n');
    return (0);
}

Measured memory_bytes: 1664