akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
const double PI = 3.14159265358979323846;

long long int N, K;



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

	long long int result = 0;

	for (long long int i = K; i <= N + 1; i++) {
		//result += i * N - (i * (i - 1) / 2) - (i * (i - 1) / 2) + 1;
		result += 1 + (N + 1 - i) * i;
	}

	cout << result % (1000000000 + 7) << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
int main(void){
	int i,l,a[26]={0};
	char s;
	while(1){
		s=getchar();
		if(s==EOF)
			break;
		if('a'<=s&&s<='z')
			a[(int)(s-'a')]++;
		else if('A'<=s&&s<='Z')
			a[(int)(s-'A')]++;
	}
	for(i=0;i<26;i++)
		printf("%c : %d\n",('a'+i),a[i]);
	return 0;
}

Measured memory_bytes: 524
import sys,bisect,math
input = sys.stdin.readline

# i が与えられたとき a1~aiまでの和を計算する( O(log n) )
def bitsum(bit,i):
    s = 0
    while i > 0:
        s += bit[i]
        i -= i&(-i)
    return s
    
# i と x が与えられたとき ai += x とする ( O(log n) )
def bitadd(bit,i,x):
    while i <= n:
        bit[i] += x
        i += i&(-i)
    return bit

n,k = map(int,input().split())
a = [int(input()) for i in range(n)]

#b[j+1]-b[i]:a[i]~a[j]
b = [0]
for i in range(n):
    b.append(b[-1]+a[i])

#c[i]:b[i]-k*i
c = [0]*(n+1)
for i in range(n+1):
    c[i] = b[i]-k*i

d = sorted(c)
for i in range(n+1):
    k = bisect.bisect_left(d,c[i])
    d[k] = d[k]-0.1
    c[i] = k+1

n = n+1
n_ = int(math.log2(n)) + 1
bit = [0] * (2**n_+1)
ass = 0
for j in range(n):
    ass += j-bitsum(bit,c[j])
    #bitsum(bit,a[j]): j-1番目までの中でa[j]以下のもの
    bit = bitadd(bit,c[j],1)


print(n*(n-1)//2-ass)

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

#define ALL(v) v.begin(), v.end()
typedef long long ll;



using namespace std;
int main() {
	string s;
	ll k;
	cin >> s >> k;

	for (int i = 0; i < k; i++)
	{
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}
	
	cout << 1 << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	string s;
	cin >> s;
	bool flag = true;
	if(s[0] != 'A')flag = false;
	int res = 0;
	for(int i = 2; i < s.size() - 1; i++){
			if(s[i] == 'C')res++;
	}
	if(res != 1)flag = false;
	for(int i = 1; i < s.size(); i++){
			if(s[i] != 'C' || !(i > 1 && i <= s.size() - 1)){
					if(!(s[i] - 'a' >= 0 && s[i] - 'a' < 26))flag = false;
			}
	}
	if(flag)cout << "AC" << endl;
	else cout << "WA" << endl;
	return 0;
}


Measured memory_bytes: 888
// Aizu Vol0 0017: Caesar Cipher
// 2017.7.31

#include <stdio.h>
#include <ctype.h>
#include <string.h>

char *gets(char *);

#define MAX 700
char key[MAX];
short half[3][26];
char buf[100 + 10], *p, *w;


int main()
{
	int i, j, k, n;
	int len;

	for (i = 0; i < MAX; i++) key[i] = 32;
	for (i = 't' - 'a', j = 'h' - 'a', k = 0; k < 26; k++) {  // th
		n = i * 26 + j;
		key[n] = k;
		if (++i >= 26) i = 0;
		if (++j >= 26) j = 0;
	}
	for (i = 'e' - 'a', k = 0; k < 26; k++) {  // th-e
		half[0][k] = i;
		if (++i >= 26) i = 0;
	}
	for (i = 'i' - 'a', j = 's' - 'a', k = 0; k < 26; k++) { // th-is
		half[1][k] = i * 26 + j;
		if (++i >= 26) i = 0; if (++j >= 26) j = 0;
	}
	for (i = 'a' - 'a', j = 't' - 'a', k = 0; k < 26; k++) { // th-at
		half[2][k] = i * 26 + j;
		if (++i >= 26) i = 0; if (++j >= 26) j = 0;
	}

	while (gets(p = buf) != NULL) {
		while (*p) {
			while (*p && !isalpha(*p)) p++;
			if (!*p) while (1);
			w = p;
			while (isalpha(*p)) p++;
			if ((len = p - w) == 3 || len == 4) {
				i = *w++ - 'a'; i = i * 26 + (*w++ - 'a');
				if ((k = key[i]) < 30) {
					if (len == 3) {
						n = *w - 'a';
						if (half[0][k] == n) goto DONE;
					} else {	// len == 4
						n = *w++ - 'a'; n = n * 26 + (*w - 'a');
						if (half[1][k] == n || half[2][k] == n) goto DONE;
					}
				}
			}
		}
DONE:	
		p = buf;
		while (*p) {
			while (*p && !isalpha(*p)) putchar(*p++);
			if (!*p) break;
			while (isalpha(*p)) {
				if ((i = (*p++ - 'a') - k) < 0) i += 26;
				putchar(i + 'a');
			}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 520
use std::collections::{VecDeque, HashMap};


fn main() {
    let (n, k) = read_tuple::<i64>();
    let scores = read_vec::<i64>();
    let t: Vec<char> = read::<String>().chars().collect();

    let win_hand = {
        let mut temp = HashMap::new();
        temp.insert('r', ('p', scores[2]));
        temp.insert('p', ('s', scores[1]));
        temp.insert('s', ('r', scores[0]));
        temp
    };
    let mut history: VecDeque<char> = VecDeque::new();
    let mut total_score = 0;
    for (i, x) in t.iter().enumerate() {
        if i as i64 - k >= 0 {
            let kth_prev = history.pop_front().unwrap();
            let hand = win_hand.get(x).unwrap();
            if kth_prev != hand.0 {
                total_score += hand.1;
                history.push_back(hand.0);
            } else {
                if i as i64 + k < n {
                    history.push_back(t[i + k as usize]);
                } else {
                    history.push_back(*x);
                }
            }
        } else {
            let hand = win_hand.get(x).unwrap();
            total_score += hand.1;
            history.push_back(hand.0);
        }
    }
    println!("{:?}", total_score);
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;


int main(){

    vector<int> prime;

    function<void(int)> sieve = [&](int n) -> void{

        //assert(n >= 2);

        vector<int> p;

        for(int i = 0; i <= n; i++){
            p.push_back(1);
        }


        p[0] = 0;
        p[1] = 0;

        for(int i = 2; i <= n; i++){
            if(i * i > n){
                break;
            }

            if(p[i] == 1){
                for(int j = i * i; j <= n; j = j + i){
                    p[j] = 0;
                }
            }
        }

        for(int i = 2; i <= n; i++){
            if(p[i] == 1) prime.push_back(i);
        }
    };

    function<int(int, int, int)> powmod = [&](int ai, int xi, int pi) -> int{

            
            if(xi == 0){
                return 1;
            }else if(xi % 2 == 1){
                return (((ll)ai) * powmod(ai, xi - 1, pi)) % pi;
            }else{
                ll tmp = powmod(ai, xi/2, pi);
                return (tmp * tmp) % pi;
            }
            
    };
    
    function<int(int,int)> invmod = [&](int a, int p) -> int{

        assert(p > 1);

        return powmod(a, p - 2, p) % MODN;
    };

    int n,m;
    cin >> n >> m;

    sieve(ceil(sqrt(m)));

    vector<ll> fact;
    fact.pback(1);

    for(int i = 1; i <= n + 35; i++){
        fact.pback((fact[i - 1] * i) % MODN);
    }

    vector<int> factor(prime.size());
    int tmp = m;

    ll ans = 1;

    while(tmp >= 2){
        bool b = true;
        rep(i,prime.size()){
            if(tmp % prime[i] == 0){
                tmp = tmp / prime[i];
                factor[i]++;
                b = false;
                break;
            }
        }

        if(b){
            ans = n;
            break;
        }
    }

    if(n - 1 > 0){
        rep(i,factor.size()){
            if(factor[i] > 0){

                ll tmp = 1;
            
                tmp = (tmp * fact[factor[i] + n - 1]) % MODN;
                tmp = (tmp * invmod(fact[n - 1], MODN)) % MODN;
                tmp = (tmp * invmod(fact[factor[i]], MODN)) % MODN;

                ans = (ans * tmp) % MODN;
                
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1592
A,B,C,X,Y = map(int,input().split())
 
sum = 0
 
if ( (A > 2*C) and (B > 2*C) ):
    sum = 2*C*max([X,Y])
 
elif (A+B > 2*C):
    sum = min([X,Y])*2*C
    if(X<Y):
        if(B > 2*C):
            sum = sum + (Y-X)*2*C
        else:
            sum = sum + (Y-X)*B
    else:
        if(A > 2*C):
            sum = sum + (X-Y)*2*C
        else:
            sum = sum + (X-Y)*A
else:
    sum = X*A + Y*B
 
print(sum)

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

signed main() {
    int n;
    cin >> n;

    vector<int> x(n), y(n), h(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }

    for (int X = 0; X <= 100; X++) {
        for (int Y = 0; Y <= 100; Y++) {

            int H = -1;
            for (int i = 0; i < n; i++) {
                if (h[i] <= 0) continue;

                int t = h[i] + abs(X - x[i]) + abs(Y - y[i]);
                if (H < 0) H = t;

                if (H != t) {
                    H = -1;
                    break;
                }
            }
            if (H < 0) continue;

            bool f = true;
            for (int i = 0; i < n; i++) {
                int t = max(0LL, H - abs(X - x[i]) - abs(Y - y[i]));
                f &= (t == h[i]);
            }

            if (f) return cout << X << " " << Y << " " << H << endl, 0;
        }
    }

    return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define M_PI 3.14159265358979323846

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }



int main()
{
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    int A,B;    
    cin >> A >> B ;
    cout << max({A+B,A-B,A*B}) << endl;

    return 0;


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <fstream>
#include <stdio.h>
#include <string>
#include <typeinfo>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
using namespace std;

int main()
{
  int A, B;
  cin >> A >> B;
  int sumYard;
  sumYard = A * B - (A * 1) - (B * 1) + 1;
  cout << sumYard << endl;
  return 0;
}


Measured memory_bytes: 256
import java.awt.Point;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int[] dx = {1, -1, 0, 0};
		int[] dy = {0, 0, 1, -1};
		char[][] s = new char[H+2][W+2];
		int[][] d = new int[H+2][W+2];
		int total = 0;
		for(int i = 1; i <= H; i++) {
			String S = sc.next();
			for(int j = 1; j <= W; j++) {
				s[i][j] = S.charAt(j-1);
				if(S.charAt(j-1) == '.')
					total++;
			}
			Arrays.fill(d[i], 10000);
		}
		Queue<Point> q = new ArrayDeque<>();
		q.add(new Point(1, 1));
		d[1][1] = 0;
		while(q.size() > 0) {
			Point p = q.poll();
			for(int i = 0; i < 4; i++) {
				if(s[p.y+dy[i]][p.x+dx[i]] == '.' && d[p.y+dy[i]][p.x+dx[i]] > d[p.y][p.x] + 1) {
					d[p.y+dy[i]][p.x+dx[i]] = d[p.y][p.x] + 1;
					q.offer(new Point(p.x+dx[i], p.y+dy[i]));		
				}
			}
		}
		if(d[H][W] == 10000)
			System.out.println(-1);
		else
			System.out.println(total - d[H][W] - 1);
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int v[n], c[n];
    REP(i,n) cin >> v[i];
    int sum = 0;
    REP(i,n) {
        cin >> c[i];
        if (v[i] > c[i]) sum += v[i] - c[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <vector>

#define el endl
#define fd fixed

using namespace std;

int main() {
  while (1) {
    int n, p, i = 0, tmp_p;
    cin >> n >> p;
    if (n == 0 && p == 0) break;
    vector<int> stone(n, 0);
    tmp_p = p;
    while (1) {
      if (tmp_p > 0) {
        stone[i]++;
        tmp_p--;
      } else {
        tmp_p = stone[i];
        stone[i] = 0;
      }
      if (stone[i] == p) break;
      i = (i+1) % n;
    }
    cout << i << el;
  }
}

Measured memory_bytes: 1196
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int,int> pr;
int main() {
	// your code goes here
	int w,h;
	while(cin >> w >> h && w!=0){
	int xs,ys,xg,yg,n,m,s,sum,c,d,x,y;
	int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
	cin >> xs>>ys>>xg>>yg >> n;
	bool map[102][102]={};	
	int color[102][102]={};
	queue<pr> q;
		color[xs][ys]=10;
		for(int i=0;i<n;i++){
			cin >> c >> d >>x >> y;
			for(int j=0;j<2+d*2;j++)
				for(int k=0;k<4-d*2;k++)
					color[x+k][y+j]=c;
		}
		map[xs][ys]=true;
		q.push(pr(xs,ys));
		while(!q.empty()){
			int f=q.front().first,s=q.front().second;
			q.pop();
			for(int i=0;i<4;i++){
					if(color[f][s]==color[f+dx[i]][s+dy[i]] && !map[f+dx[i]][s+dy[i]]){
						q.push(pr(f+dx[i],s+dy[i]));
						map[f+dx[i]][s+dy[i]]=true;
					}
			}
		}
		if(map[xg][yg])
		cout << "OK" << endl;
		else
		cout << "NG" << endl;
	}
	return 0;
}

Measured memory_bytes: 1252
S = input()
n = len(S)
shift_max = [0]*(n+1)

big_run = 0
for i in range(n):
    if S[i] == '<':
        big_run += 1
    else:
        big_run = 0
    shift_max[i+1] = big_run
small_run = 0
for i in reversed(range(n)):
    if S[i] == '>':
        small_run += 1
    else:
        small_run = 0
    shift_max[i] = max(shift_max[i],small_run)

print(sum(shift_max))



Measured memory_bytes: 72656
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int[] num = new int[4];

		num[0] = Integer.parseInt(s.substring(0, 1));
		num[1] = Integer.parseInt(s.substring(1, 2));
		num[2] = Integer.parseInt(s.substring(2, 3));
		num[3] = Integer.parseInt(s.substring(3, 4));

		String ans = calc(num, 0, "+", 0);
		if (ans.length() < 4) {
			System.out.println("");
		} else {
			String a = String.valueOf(num[0]);
			for (int i = 1; i <= 3; i++) {
				a = a + String.valueOf(ans.charAt(i));
				a = a + String.valueOf(num[i]);
			}
			a = a + "=7";
			System.out.println(a);
		}
	}

	public static String calc(int[] num, int numind, String op, int sum) {
		int n = num[numind];
		if (op.equals("-"))
			n *= -1;

		int newsum = sum + n;
		if (numind >= 3) {
			if (newsum == 7) {
				return op;
			} else {
				return "";
			}
		} else {
			String s = calc(num, numind + 1, "+", newsum);
			if (s.length() > 0) {
				return op + s;
			} else {
				s = calc(num, numind + 1, "-", newsum);
				if (s.length() > 0)
					return op + s;
				return s;
			}
		}
	}
}

Measured memory_bytes: 22612
#include <map>
#include <cstdio>
main(){std::map<int,int>z={{12,6},{13,10},{14,12},{15,14},{16,27},{17,33},{23,7},{24,9},{25,12},{26,23},{27,30},{34,5},{35,8},{36,20},{37,27},{45,5},{46,17},{47,26},{56,12},{57,23},{67,10}};for(int a,b,h,m,H,M;scanf("%d%d%d%d%d%d",&a,&h,&m,&b,&H,&M)>5;printf("%d\n",(h+H)*50))if(m+=h*60,M+=H*60,h=z[a*10+b],H=0,h<27&&((1050<=m&&m<=1170)||(1050<=M&&M<=1170)))H=(h&1),h/=2;}

Measured memory_bytes: 1036
// Created by Tanuj Jain
#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 pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in","r",stdin);
	//freopen("outputf.in","w",stdout);
	//#endif

	string st,t;
	cin>>st>>t;
	bool ok=true;
	for(int i=0;i<st.length();i++)
		if(st[i]!=t[i])
		{
			ok=false;
			break;
		}
		if(!ok)
		{
			cout<<"No";
		}
		else if(ok && t.length()-st.length()==1)
		{
			cout<<"Yes";
		}
	
}

Measured memory_bytes: 3640
import math
from itertools import accumulate
n, k = map(int, input().split())
As = list(map(int, input().split()))
for i in range(min(41, k)):
  _As = [0]*(n+1)
  for j in range(n):
    l = max(0, j - As[j])
    r = min(n - 1, j + As[j])
    _As[l] += 1
    _As[r+1] -= 1
  As = list(accumulate(_As))[:-1]
print(' '.join([str(A) for A in As]))

Measured memory_bytes: 210716
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


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

  cout << (1110 - i) << endl;

  return 0;
}


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

using namespace std;

int main(){
    int N;
    string S;
    long long ans = 0;
    long long i, j, k, rc=0, gc=0, bc=0;
    cin >> N >> S;
    for (int l = 0; l < N;l++)
    {
        if(S[l]=='R'){
            rc++;
        }
        else if(S[l]=='G'){
            gc++;
        }
        else if(S[l]=='B'){
            bc++;
        }
    }
    ans = rc * gc * bc;
    for (i = 0; i < N-2;i++)
    {
        for (j = i+1; j < N;j++){
            if(2*j-i >= N){
                break;
            }
            if(S[j] != S[i]){
                if(S[2*j-i] != S[i] && S[2*j-i] != S[j]){
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
A_NUM_MAX = 10001


def counting_sort(A):
    B = [None] * len(A)
    C = [0] * A_NUM_MAX

    for a in A:
        C[a] += 1

    for i in range(1, A_NUM_MAX):
        C[i] += C[i - 1]

    for a in reversed(A):
        B[C[a] - 1] = a
        C[a] -= 1

    return B


n = int(input())
A = list(map(int, input().split()))

B = counting_sort(A)

print(*B)


Measured memory_bytes: 224504
def exec():
    a,b,k = map(int, input().split())
    if(k >= (b-a+1)/2):
        for i in range(a,b+1):
            print(i)
    else:
        arr = []
        for i in range(k):
            arr.append(i+a)
        for i in reversed(range(k)):
            arr.append(b - i)
        for c in arr:
            print(c)


if __name__ == "__main__":
    exec()


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>

int main(){
	int a[12];
	for(int i=0;i<12;i++)scanf("%d",a+i);
	std::sort(a,a+12);
	puts(
		a[0]==a[1]&&a[1]==a[2]&&a[2]==a[3] &&
		a[4]==a[5]&&a[5]==a[6]&&a[6]==a[7] &&
		a[8]==a[9]&&a[9]==a[10]&&a[10]==a[11] ?
		"yes" : "no"
	);
}

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

int main() {
    int N; cin >> N;
    vector<long long> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];

    long long res = 0;
    for(int i=0; i<N; ++i) {
        for(int j=i+1; j<N; ++j) {
            res += A[i] * A[j];
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>
static const int MAXN = 302;

int n, m;
int a[MAXN][MAXN];
bool rm[MAXN] = { false };

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) {
            scanf("%d", &a[i][j]); --a[i][j];
        }

    int ans = n + 1;
    for (int rep = 0; rep < m; ++rep) {
        static int ct[MAXN];
        for (int i = 0; i < m; ++i) ct[i] = 0;
        for (int i = 0; i < n; ++i) {
            int sel = -1;
            for (int j = 0; j < m; ++j)
                if (!rm[a[i][j]]) { sel = a[i][j]; break; }
            ++ct[sel];
        }
        std::pair<int, int> cur(-1, -1);
        for (int i = 0; i < m; ++i) cur = std::max(cur, std::make_pair(ct[i], i));
        ans = std::min(ans, cur.first);
        rm[cur.second] = true;
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
const int mod=(int)1e9+7;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); 
   	int n,ctr=0;
   	cin>>n;
   	int a[n+1];
   	for(int x=1;x<=n;x++) cin>>a[x];
   	for(int x=1;x<=n;x++){
   		if(a[x]==x) swap(a[x],a[x+1]),ctr++;
   	}
   	cout<<ctr;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=2e5+5;
const ll inf=1e17;



int main()
{
    idfc;


    int n;
    cin>>n;
    n=!n;
    cout<<n;

    return 0;
}

Measured memory_bytes: 3648
using System;

class Program
{
    static void Main(string[] args)
    {
        var c = Read();
        string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        if (alphabets.Contains(c))
        {
            Console.WriteLine("A");
        }
        else
        {
            Console.WriteLine("a");
        }
    }

    private static string Read() => Console.ReadLine();
    private static char[] ReadChars() => Array.ConvertAll(Read().Split(), a => a[0]);
    private static int ReadInt() => int.Parse(Read());
    private static long ReadLong() => long.Parse(Read());
    private static double ReadDouble() => double.Parse(Read());
    private static int[] ReadInts() => Array.ConvertAll(Read().Split(), int.Parse);
    private static long[] ReadLongs() => Array.ConvertAll(Read().Split(), long.Parse);
    private static double[] ReadDoubles() => Array.ConvertAll(Read().Split(), double.Parse);
}

Measured memory_bytes: 25796
#include <stdio.h>
 
int main(void) {
    long prm[78498]={2,3},n,m,cnt=2;
    int judge;
    for(n=5;n<=999999;n+=2) {
        
        for(judge=1,m=0;prm[m]*prm[m]<=n;m++) {
            if(!(n%prm[m])) {
                judge=0;
                break;
            }
        }
        if(judge) {
            prm[cnt++]=n;
        }
    }
    while(scanf("%ld",&n)!=EOF) {
        for(cnt=0;prm[cnt]<=n;cnt++){}
        printf("%ld\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 1212
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

A, B, C, D = MAP()
print(max(A*B, C*D))


Measured memory_bytes: 13600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 5e5+5;
// check for forloop
// take input
// overflow
// intialize variable
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    ll n,k;
    cin>>n>>k;
    if(k-n>2019){
        cout<<0;
    }
    else{
        ll ans=2019;
        for(ll i=n;i<k;i++){
            for(ll j=i+1;j<=k;j++){
                ans=min(ans,ll((i*j)%2019));
            }
        }
        cout<<ans;
    }
}


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

using namespace std;

int main() {
	int d, g;
	cin >> d >> g;
	g /= 100;
	int p[11], c[11];
	for (int i = 0; i < d; i++)
		cin >> p[i] >> c[i];
	int m = 1e9;
	for (int i = 0; i < 1 << d; i++) {
		int s = 0, x = 0;
		for (int j = 0; j < d; j++)
			if (i & 1 << j) s += c[j] / 100 + p[j] * (j + 1), x += p[j];
		if (s >= g) goto pnz;
		for (int j = d; j--;) {
			if (i & 1 << j) continue;
			for (int k = 0; k < p[j] - 1; k++) {
				s += j + 1;
				x++;
				if (s >= g) goto pnz;
			}
		}
		continue;
	pnz:
		m = min(m, x);
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
# if true

# include <iostream>
# include <string>

int main()
{


	std::string s;
	std::cin >> s;
	
	long long result{};

	long long wNum{};
	for (long long i = 0; i < s.size(); ++i)
	{
		if (s[s.size() - i - 1] == 'B')
		{
			result += wNum;
		}
		else ++wNum;

	}

	std::cout << result;


	return 0;
}


# endif

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

    public static class TopologicalSort_DFS {

        boolean hasCycle;
        LinkedList<Integer> sortedOrder;
        TreeSet<Integer> unmarkedV;
        boolean[] tempMark;

        public TopologicalSort_DFS(WeightedDigraph graph) {
            tempMark = new boolean[graph.numVertex];
            unmarkedV = new TreeSet<Integer>();
            for (int v = 0; v < graph.numVertex; v++) {
                unmarkedV.add(v);
            }
            sortedOrder = new LinkedList<Integer>();

            try {
                while (!unmarkedV.isEmpty()) {
                    int v = unmarkedV.first();
                    dfs(v, graph);
                }
            } catch (Exception ex) {
                hasCycle = true;
                sortedOrder.clear();
            }
        }

        private void dfs(int vert, WeightedDigraph graph) throws Exception {
            if (tempMark[vert]) {
                throw new Exception("cycle deteced v:" + vert);
            }
            if (unmarkedV.contains(vert)) {
                tempMark[vert] = true;
                for (WeightedDigraph.Edge edge : graph.srcEdges[vert]) {
                    dfs(edge.targetVertex, graph);
                }
                unmarkedV.remove(vert);
                tempMark[vert] = false;
                sortedOrder.addFirst(vert);
            }
        }

        public boolean hasCycle() {
            return hasCycle;
        }

        public Iterator<Integer> sortedOrder() {
            return sortedOrder.iterator();
        }
    }

    public static class WeightedDigraph {

        int numVertex;
        int numEdge;

        List<Edge>[] srcEdges;

        @SuppressWarnings("unchecked")
        public WeightedDigraph(int numV, int numE) {
            this.numVertex = numV;
            this.numEdge = numE;
            srcEdges = new List[numV];

            for (int i = 0; i < numV; i++) {
                srcEdges[i] = new ArrayList<Edge>();
            }
        }

        public void addEdge(int srcVertex, int targetVertex, int weight) {
            Edge e = new WeightedDigraph.Edge(srcVertex, targetVertex, weight);
            srcEdges[srcVertex].add(e);
        }

        public static class Edge {

            int srcVertex;
            int targetVertex;
            int weight;

            public Edge(int srcVertex, int targetVertex, int weight) {
                this.srcVertex = srcVertex;
                this.targetVertex = targetVertex;
                this.weight = weight;
            }
        }

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int v = in.nextInt();
        int e = in.nextInt();
        WeightedDigraph graph = new WeightedDigraph(v, e);
        while (e-- > 0) {
            graph.addEdge(in.nextInt(), in.nextInt(), 1);
        }
        TopologicalSort_DFS topSort = new TopologicalSort_DFS(graph);
        System.out.println(topSort.hasCycle() ? 1 : 0);
    }
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, d;

int main() {
    cin >> n >> d;
    li res = 0;
    rin{
        li x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3620
main :: IO ()
main = do
  [_n, _m, x, y] <- map read . words <$> getLine
  xs <- map read . words <$> getLine
  ys <- map read . words <$> getLine
  print $ f x y xs ys

data Result =
  War | NoWar
  deriving Eq

instance Show Result where
  show War = "War"
  show NoWar = "No War"

f :: Int -> Int -> [Int] -> [Int] -> Result
f x y xs ys =
  if any (\z -> z > maximum xs && z <= minimum ys) [x + 1 .. y]
  then NoWar
  else War


Measured memory_bytes: 1020
n,m = [int(i) for i in input().split()]
ks = []
for i in range(m):
    x = list(map(int,input().split()))
    ks.append(x)
p = list(map(int,input().split()))


ans = 0
for i in range(2**n):
    bina = list(reversed(format(i, '010b')))
    flag = True
    for j in range(m):
        count = 0
        sw = ks[j]
        for k in range(1,len(sw)):
            if bina[sw[k]-1] == "1":
                count += 1
        if count % 2 != p[j]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if (a*b % 2)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n, a, b, c;
    cin >> n >> a >> b >> c;

    vector<int> l(n);
    int upper = 1;
    for(int in=0;in<n;++in) {
        cin >> l[in];
        upper *= 4;
    }

    bool flga, flgb, flgc;
    int braa, brab, brac, allbra, onebra;
    int ans = 10000, anstmp;
    for(int iu=0;iu<upper;++iu) {
        flga = false;
        flgb = false;
        flgc = false;
        braa = 0;
        brab = 0;
        brac = 0;
        anstmp = 0;
        allbra = iu;
        for(int in=0;in<n;++in) {
            onebra = allbra % 4;
            if(onebra==1) { 
                braa += l[in];
                if(flga) anstmp += 10;
                flga = true;
            }
            else if(onebra==2) { 
                brab += l[in];
                if(flgb) anstmp += 10;
                flgb = true;
            }
            else if(onebra==3) { 
                brac += l[in];
                if(flgc) anstmp += 10;
                flgc = true;
            }
            else ;
            allbra /= 4;
        }
        anstmp += abs(braa-a);
        anstmp += abs(brab-b);
        anstmp += abs(brac-c);
        if(flga&flgb&flgc) chmin(ans, anstmp);
    }

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


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

int top,S[1000];

void push(int x){
	S[++top]=x;
}
int pop(){
	top--;
	return S[top+1];
}
int main(){
	int a,b;
	top=0;
	char s[100];
	while(scanf("%s",s)!=EOF){
		if(s[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}
		else if(s[0]=='-'){
			b=pop();
			a=pop();
			push(a-b);
		}
		else if(s[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}
		else{
			push(atoi(s));
		}
	}
	printf("%d\n",pop());
	}

Measured memory_bytes: 2664
def count_k_or_more(b, N, K):
    # 0 % bがcountに含まれている場合は-1する必要がある
    # しかし0 % b = 0でこれがcountに含まれるのはK = 0の場合のみ
    # K = の場合はcount = Nになるのでそのままreturnする
    if K == 0:
        return N

    # N = pb + r
    p = N // b
    r = N % b

    count = p * max(b - K, 0) + max(r + 1 - K, 0)
    return count


if __name__ == '__main__':
    N, K = [int(v) for v in input().split()]

    total = 0
    for b in range(1, N + 1):
        total += count_k_or_more(b, N, K)

    print(total)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	str s;
	cin >> s;
	ll ans = 0;
	rep(i, s.size() / 2)
	{
		if (s[i] != s[s.size() - i - 1])
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <math.h>
int main(void){
double p[4][2],a;
int n,i,j;
scanf("%d",&n);
while(n--){
for(i=0;i<4;i++)
for(j=0;j<2;j++)
scanf("%lf",&p[i][j]);
a=(p[2][0]-p[3][0])*(p[0][1]-p[1][1])-(p[0][0]-p[1][0])*(p[2][1]-p[3][1]);
if(fabs(a)<1e-10)
puts("YES");
else
puts("NO");
}
return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=250005;
ull p1=233,p2=1;
int n;
ll ans;
ull f[N],f2[N];
char s[N];
map<ull,int> mp;
int main(){
	scanf("%d",&n);
	ull tmp=p1;
	for(int i=1;i<=63;i++){
		p2*=tmp;
		tmp*=tmp;
	}
	scanf("%s",s+1);
	f[0]=0,f2[0]=1;
	for(int i=1;i<=n;i++){
		f[i]=f[i-1],f2[i]=f2[i-1];
		if(s[i]=='+')f[i]+=f2[i];
		else if(s[i]=='-')f[i]-=f2[i];
		else if(s[i]=='>')f2[i]*=p1;
		else if(s[i]=='<')f2[i]*=p2;
		mp[f[i]]++;
	}
	for(int i=1;i<=n;i++){
		ans+=mp[f[n]*f2[i-1]+f[i-1]];
		mp[f[i]]--;
	} 
	printf("%lld",ans);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int top3 = N / 10;
  int bottom3 = N % 1000;
  
  if (top3 % 111 == 0 || bottom3 % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl; 
  }
    
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())
B = [int(i) for i in input().split()] 

max_A =[B[0]]
B.append(B[N-2])

for i in range(N-1):
    max_A.append(min(B[i],B[i+1]))

print(sum(max_A))

Measured memory_bytes: 3060
def search():
    for i in range(N+1):
        for j in range(N+1):
            k = N - i - j
            if k < 0:
                break
            if 10000*i + 5000*j + 1000*k == Y:
                return ("{0} {1} {2}".format(i, j, k))
    return "-1 -1 -1"

N, Y = map(int, input().split())
print(search())

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}


//#########################################




int main() {

    int a=D(),b=D();
    if(b>=(a%500)){
        cout<<"Yes";

    } else cout<<"No";


}


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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PN() putchar('\n')
#define MP make_pair
#define PB push_back
#define EB emplace_back

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
void print() {putchar('\n');}
template<typename T, typename... U>
void print(T head, U... tail) {
    cout << head << " ";
    print(tail...);
}

const int MOD = 1000000007;
#define MAX_N 200005
LL a[MAX_N];

int main()
{
    int n;
    RI(n);
    REP(i, n) {
        scanf("%lld", &a[i]);
    }
    LL s = a[0], r = 0;
    REP(i, 1, n) {
        r += a[i];
    }
    LL m = llabs(s - r);
    REP(i, 1, n-1) {
        s += a[i];
        r -= a[i];
        m = min(m, llabs(s - r));
    }
    printf("%lld\n", m);
    return 0;
}


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

int main()
{
    char a,b;
    cin >> a >> b ;
    if(a == 'H' && b == 'H') cout << "H\n" ;
    else if(a == 'D' && b == 'D') cout << "H\n" ;
    else if(a == 'H' && b == 'D') cout << "D\n" ;
    else
        cout << "D\n" ;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = max(a*b,c*d);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3616
n = int(input())
alice = 0
bob = 0
cards = [int(val) for val in input().split()]

cards = sorted(cards, reverse=True)

for i in range(n):
    if i % 2 == 0:
        alice += int(cards[i])
    else:
        bob += int(cards[i])
        
print(alice - bob)

Measured memory_bytes: 3060
#include <stdio.h>
#define N_MAX 101

int main(){
  int n,i,j,k,x,u;
  int adj[N_MAX][N_MAX]={0};
    
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&x);
      adj[u][x]=1;
    }
  }
  
  for(i=1;i<=n;i++){
    for(j=1;j<n;j++){
      printf("%d ",adj[i][j]);
    }
    printf("%d\n",adj[i][j]);
  }
  return 0;
}



Measured memory_bytes: 2112
mod = 998244353


class Combination:
    def __init__(self, N):
        self.fac = [1] * (N + 1)
        for i in range(1, N + 1):
            self.fac[i] = (self.fac[i - 1] * i) % mod
        self.invmod = [1] * (N + 1)
        self.invmod[N] = pow(self.fac[N], mod - 2, mod)
        for i in range(N, 0, -1):
            self.invmod[i - 1] = (self.invmod[i] * i) % mod

    def calc(self, n, k):  # nCk
        return self.fac[n] * self.invmod[k] % mod * self.invmod[n - k] % mod


N, M, K = map(int, input().split())
C = Combination(N)

ans = 0
for k in range(K + 1):
    tmp = C.calc(N - 1, N - k - 1) * M * pow(M - 1, N - k - 1, mod) % mod
    ans = (ans + tmp) % mod

print(ans)


Measured memory_bytes: 24636
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,a;
	int i,m=0,m1=0,x=0,y=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		if(m<a){
			m1=m;
			m=a;
			x=i+1;
		}
		else if(m1<a){
			m1=a;
			y=i+1;
		}
	}
	for(i=1;i<=n;i++){
		if(i==x){
			printf("%d\n",m1);
		}
		else{
			printf("%d\n",m);
		}
	}
	return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type
summation(InputIterator first, InputIterator last) {
  using T = typename InputIterator::value_type;
  T *p = new T();
  const auto sum = std::accumulate(first, last, *p);
  delete p;
  return sum;
}
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, m;
  std::cin >> n >> m;
  std::vector<std::set<int>> no(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    std::cin >> a >> b;
    a--;
    b--;
    no[a].insert(b);
    no[b].insert(a);
  }

  std::vector<bool> flag(n, false);
  flag[0] = true;

  std::multimap<int, std::vector<bool>> q;
  for (const auto i : no[0]) {
    q.insert({i, flag});
  }
  int count = 0;

  while (!q.empty()) {
    std::multimap<int, std::vector<bool>> tmp;

    for (auto i : q) {
      i.second[i.first] = true;
      if (std::all_of(i.second.cbegin(), i.second.cend(), [] (auto i) {
        return i;})) {
        count++;
      } else {
        for (const auto j : no[i.first]) {
          if (!i.second[j]) {
            tmp.insert({j, i.second});
          }
        }
      }
    }

    std::swap(q, tmp);
  }

  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
#include<string.h>
int Partition(int *,int *,char *,int,int);
void QSort(int *,int *,char *,int,int);
int main()
{
  int i,n,s=0;
  int A[200000],B[200000];
  char ch,C[100000];
   
  scanf("%d%c",&n,&ch);
  for(i=0;i<n;i++){
    scanf("%c%c%d%c",&C[i],&ch,&A[i],&ch);
    B[i]=i;
  }

  QSort(A,B,C,0,n-1);
  for(i=0;i<n;i++){
    if(B[i]>B[i+1] && A[i]==A[i+1]){
      s=1;
      break;
    }
  }
  if(s==0)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",C[i],A[i]);
  }
  return 0;
}

void QSort(int *A,int *B,char *C,int p,int r)
{
  int q;
  if(p<r){
    q=Partition(A,B,C,p,r);
    QSort(A,B,C,p,q-1);
    QSort(A,B,C,q+1,r);
  } 
}


int Partition(int *A,int *B,char *C,int p,int r)
{
  int x,i,j,temp;
  char ch;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
      temp=B[i];
      B[i]=B[j];
      B[j]=temp;
      ch=C[i];
      C[i]=C[j];
      C[j]=ch;
    }
    
  }
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp; 
  temp=B[i+1];
  B[i+1]=B[r];
  B[r]=temp;
  ch=C[i+1];
  C[i+1]=C[r];
  C[r]=ch;
  return i+1;
}  

Measured memory_bytes: 1492