akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    int key;
    Node *prev, *next;
};

Node *nil;

void init(){ //双方向リストの初期化
    nil = (Node *)malloc(sizeof(Node));
    nil -> next = nil;
    nil -> prev = nil;
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x -> key = key;
    x -> next = nil -> next;
    nil -> next -> prev = x;
    nil -> next = x;
    x -> prev = nil;
}

Node* listSearch(int key){
    Node *cur = nil -> next;
    while(cur != nil && cur -> key != key){
        cur = cur -> next;
    }
    return cur;
}

void deleteNode(Node *t){
    if(t == nil) return;
    t -> prev -> next = t -> next;
    t -> next -> prev = t -> prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil -> next);
}

void deleteLast(){
    deleteNode(nil -> prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void printNode(){
    Node *p = nil -> next;
    while(p != nil){
        if(p -> prev != nil){printf(" ");}
        printf("%d", p -> key);
        p = p -> next;
    }
    printf("\n");
}

int main(){
    int n;
    scanf("%d", &n);

    Node node;
    init();

    char c[12];
    int k;

    for(int i=0; i<n; i++){
        scanf("%s",c);

        if(strlen(c) == 6){
            scanf("%d",&k);
            if(c[0] == 'i'){
                insert(k);
            } else if(c[0] == 'd'){
                deleteKey(k);
            }
        } else {
            if(c[6] == 'F'){
                deleteFirst();
            } else if(c[6] == 'L'){
                deleteLast();
            }
        }
    }
    printNode();
    return 0;
}


Measured memory_bytes: 33824
import sys
S = str(sys.stdin.readline()).strip()

S1 = S.replace(S[0],'')
if len(S1) != 2:
  print('No')
  exit()
  
S2 = S1.replace(S1[0],'')
if len(S2) == 0:
  print("Yes")
else:
  print("No")

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

using namespace std;
int a[55][5],b[55][5];
int main()
{
    int m,n,ans;
    cin >> m >> n;
    for(int i=0;i<m;i++)
    {
        cin >> a[i][1] >> a[i][2];
    }
    for(int i=0;i<n;i++)
    {
        cin >> b[i][1] >> b[i][2];
    }
    for(int i=0;i<m;i++)
    {
        int k=1000000000;
        for(int j=0;j<n;j++)
        {
            if(abs(a[i][1]-b[j][1])+abs(a[i][2]-b[j][2])<k)
            {
                k=abs(a[i][1]-b[j][1])+abs(a[i][2]-b[j][2]);
                ans=j+1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
constexpr int dx[] = {1, 0, -1,  0};
constexpr int dy[] = {0, 1,  0, -1};
int h, w;
string field[51];
bitset<51> b[51];
int bfs() {
	deque<tuple<int, int, int>> dq{mt(0, 0, 0)};
	int y, x, ny, nx, cnt = 0;
	b[0].set(0);
	while (!dq.empty()) {
		tie(cnt, y, x) = dq.front(); dq.pop_front();
		rep(i, 0, 4) {
			ny = y + dy[i];
			nx = x + dx[i];
			if (0 <= ny && ny < h && 0 <= nx && nx < w && !b[ny][nx] && field[ny][nx] == '.') {
				if (ny == h - 1 && nx == w - 1) {
					return cnt + 1;
				}
				b[ny].set(nx);
				dq.eb(mt(cnt + 1, ny, nx));
			}
		}
	}
	return 0;
}
int solve() {
	cin >> h >> w;
	rep(i, 0, h) {
		cin >> field[i];
	}
	int ans = bfs();
	if (ans == 0)
		return -1;
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (field[i][j] == '#')
				++ans;
		}
	}
	return h * w - ans - 1;
}
int main() {
	print(solve());
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()

int n;
int c[200000];
vector<int> edge[200000];


int cnt[200000];
long long ans[200000];


void merge(unordered_map<int,int> &a, unordered_map<int,int> &b) {
	if (a.size() < b.size()) {
		swap(a, b);
	}
	for (auto x : b) {
		a[x.first] += x.second;
	}
}

unordered_map<int,int> dfs(int u, int par) {
	unordered_map<int, int> ret;
	for (int v: edge[u]) {
		if (v == par)continue;
		auto mp = dfs(v, u);
		cnt[u] += cnt[v];

		auto it = mp.find(c[u]);
		if (it != mp.end()) {
			long long si = cnt[v] - it->second;
			ans[c[u]] -= (si + 1) * si / 2;
		}
		else {
			ans[c[u]] -= (long long)(cnt[v] + 1) * cnt[v] / 2;
		}
		merge(ret, mp);
	}

	cnt[u] ++;
	ret[c[u]] = cnt[u];

	if (par == -1) {
		rep(i, n) {
			auto it = ret.find(i);
			if (it != ret.end()) {
				long long si = n - it->second;
				ans[i] -= (si + 1) * si / 2;
			}
			else {
				ans[i] -= (long long)(n + 1) * n / 2;
			}
		}
	}

	return ret;
}


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

	cin >> n;
	rep(i, n)cin >> c[i];
	rep(i, n)c[i]--;

	rep(i,n-1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	dfs(0, -1);

	long long sum = (long long)(n + 1) * n / 2;
	rep(i,n) {
		cout << sum + ans[i] << endl;
	}

	

	return 0;
}


Measured memory_bytes: 55508
import java.lang.ArithmeticException

fun main() {
	val n = readLine()!!.toInt()
	val a = readLine()!!.split(" ").map {it.toLong()}
	var r = 1L
	if(a.contains(0L)) {
		println(0)
		return
	}
	try {
		for(i in a)
			r = Math.multiplyExact(r,i)
		if(r>1000_000_000_000_000_000)
			throw ArithmeticException()
	} catch(e:ArithmeticException) {
		println(-1)
		return
	}
	println(r)
}


Measured memory_bytes: 61412
use std::vec::Vec;

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> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (a, b, c) = {
        let v: Vec<i64> = read_vec();
        (v[0], v[1], v[2])
    };

    if a <= c && c <= b {
       println!("Yes");
    } else {
       println!("No");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;
ll max(ll a, ll b){return a > b ? a : b;}
ll min(ll a, ll b){return a < b ? a : b;}

int a[101];
int dp[100010];
int n, k;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    for(int i=k; i>k-a[1]; i--)
    {
        dp[i]=1;
    }
    for(int i=k-a[1]; i>=0; i--)
    {
        bool ok=0;
        for(int j=1; j<=n; j++)
        {
            if(i+a[j]>k)
            {
                dp[i]=1;
                break;
            }
            else if(dp[i+a[j]]==1)
            {
                dp[i]=2;
                ok=1;
                break;
            }
        }
        if(!ok) dp[i]=1;
    }
    for(int i=1; i<=n; i++)
    {
        if(dp[a[i]]==1)
        {
            cout << "First";
            return 0;
        }
    }
    cout << "Second";
}

//TODO: 56
//come back to 50D, 55D, DP-J


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9+5;
int main()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    int a[n+5];
    for(int i=0;i<n;i++) cin>>a[i];
    int dp[n+5];
    for(int i=0;i<n;i++) dp[i]=inf;
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+k;j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
import heapq
from collections import defaultdict

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


work = defaultdict(list)

for i in range(N):
    a,b = map(int, input().split())
    work[a-1].append(-b)



# 終了日から１日前、２日前、...の順で仕事を選ぶ
current_work = []
ans = 0
for i in range(M):
    if i in work.keys():
        for j in work[i]:
            heapq.heappush(current_work, j)

    if current_work:
        #heapq.heapify(current_work)
        ans += -1 * heapq.heappop(current_work)

print(ans)

Measured memory_bytes: 27652
#include<cstdio>
#include<bits/stdc++.h>
#include<cstring>
#include<algorithm>
 #include<iostream>
void px(int a[],int x)
{ int temp,max,t;
  for(int i=0;i<x;i++)
 {
   max=a[i];
   t=i;
for(int q=i+1;q<x;q++)
  if(max<a[q])
  {
  max=a[q];
  t=q;
}
temp=a[t];a[t]=a[i];a[i]=temp;

}
	
	
}
int main()
{
int a[55];
int x,y;
while(scanf("%d%d",&x,&y)!=EOF)
{  memset(a,0,sizeof(a));
	for(int i=0;i<x;i++)
	 scanf("%d",&a[i]);
	px(a,x);
	 long long sum=0;
	 for(int q=0;q<y;q++)
	 sum=sum+a[q];
	 
	printf("%lld\n",sum);
	
	
	
}

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(n) for (int i = 0; i < (n); ++i)
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n,100000);
    vector<int> b(n-1);
    rep(n-1) cin >> b[i];

    rep(n-1){
        a[i] = min(a[i],b[i]);
        a[i+1] = min(a[i+1],b[i]);
    }

    ll ans = 0;
    rep(n) ans+=a[i];
    cout<<ans;
}

Measured memory_bytes: 256
from functools import reduce
import bisect

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10

    # mod用
    p=10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    

    N = int(input().rstrip())
    # A = list(map(int, input().split()))
    A = list(int(_) for _ in input().split())
    # A = list(input().split())
    A.sort()
    flag = False
    if A[0] == 0 and N%2 == 1:
        flag = True
        for i in range(N):
            if A[i] != (i + 1) // 2 * 2:
                flag = False
                break
    if A[0] == 1 and N%2 == 0:
        flag = True
        for i in range(N):
            if A[i] != i // 2 * 2 + 1:
                flag = False
                break
    if flag:
        print(2**(N//2) % p)
    else:
        print(0)
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 14436
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#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 Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
#define oset tree<pi, null_type,greater<pi>, rb_tree_tag,tree_order_statistics_node_update>


int main()
{
    string s;
    int n;
    cin >> n >> s;
    int cnt = 0;
    for(int i=0; i<n; ){
        char c = s[i];
        while(i<n && s[i]==c)i++;
        cnt++;
    }
    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 3688
using System;
using System.Collections.Generic;

namespace ABC088_D___Grid_Repainting
{
    class Program
    {
        static void Main(string[] args)
        {
            var HW = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var height = HW[0];
            var width = HW[1];
            var map = new int[width, height];
            var wallCount = 0;
            for (int i = 0; i < height; i++)
            {
                var read = Console.ReadLine();
                for (int j = 0; j < width; j++)
                {
                    map[j, i] = read[j] == '#' ? -1 : 0;
                    wallCount -= map[j, i];
                }
            }

            var searchQueue = new Queue<Point>();
            searchQueue.Enqueue(new Point(0, 0));
            while (searchQueue.Count != 0)
            {
                var current = searchQueue.Dequeue();
                var currentSteps = map[current.x, current.y];
                if (current.x != 0 && map[current.x - 1, current.y] == 0)
                {
                    map[current.x - 1, current.y] = currentSteps + 1;
                    searchQueue.Enqueue(new Point(current.x - 1, current.y));
                }
                if (current.x != width - 1 && map[current.x + 1, current.y] == 0)
                {
                    map[current.x + 1, current.y] = currentSteps + 1;
                    searchQueue.Enqueue(new Point(current.x + 1, current.y));
                }
                if (current.y != 0 && map[current.x, current.y - 1] == 0)
                {
                    map[current.x, current.y - 1] = currentSteps + 1;
                    searchQueue.Enqueue(new Point(current.x, current.y - 1));
                }
                if (current.y != height - 1 && map[current.x, current.y + 1] == 0)
                {
                    map[current.x, current.y + 1] = currentSteps + 1;
                    searchQueue.Enqueue(new Point(current.x, current.y + 1));
                }
            }
            var minSteps = map[width - 1, height - 1];
            Console.WriteLine(minSteps == 0 ? -1 : height * width - wallCount - minSteps - 1);
        }
    }
    struct Point
    {
        public int x;
        public int y;
        public Point(int _x, int _y)
        {
            x = _x;
            y = _y;
        }
    }
}


Measured memory_bytes: 13268
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
asum=0
bsum=0
pointer=0
while pointer<m and bsum+b[pointer]<=k:
	bsum+=b[pointer]
	pointer+=1
ans=pointer
for i in range(n):
	asum+=a[i]
	while asum+bsum>k and pointer>=0:
		pointer-=1
		bsum-=b[pointer]
	if asum+bsum>k:
		break
	ans=max(ans,(i+1)+pointer)
print(ans)

Measured memory_bytes: 117244
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author __shangu__
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DChristmas solver = new DChristmas();
        solver.solve(1, in, out);
        out.close();
    }

    static class DChristmas {
        private long[] memo;
        private long[] tot;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            memo = new long[n + 10];
            tot = new long[n + 10];
            tot[0] = 1;
            memo[0] = 1;
            long k = in.nextLong();

            for (int i = 1; i <= n; ++i) {
                tot[i] = tot[i - 1] * 2 + 3;
                memo[i] = memo[i - 1] * 2 + 1;
//            out.printf("%d: %d %d\n", i, tot[i], memo[i]);
            }

            out.println(count(n, k));
        }

        private long count(int n, long k) {
            if (k == 0) return 0;
            if (n == 0) return 1;
            if (k == tot[n]) return memo[n];
            if (k <= tot[n - 1] + 1) return count(n - 1, k - 1);
            return count(n - 1, tot[n - 1]) + 1 + count(n - 1, k - tot[n - 1] - 2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 21460
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.next();
        int n = s.length();
        long ans = 0;
        for (int i = 0; i < (1 << n - 1); i++) {
            long res = (long) s.charAt(0) - '0';
            for (int j = 0; j < n - 1; j++) {
                if (((i >> j) & 1) == 1) {
                    ans += res;
                    res = (long) s.charAt(j + 1) - '0';
                } else {
                    res *= 10;
                    res += (long) s.charAt(j + 1) - '0';
                }
            }
            ans += res;
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
signed main() {
    int a,b,c;
    cin >> a >> b >> c ;
        if (a <= b*c){
      cout << "Yes" << endl;
    } 
    else {
      cout << "No" << endl;
    }
    

   
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll ans = 0;
    if(n)
    ans = ans+(n*(n-1))/2;
    if(m)
    ans = ans+(m*(m-1))/2;
    cout<<ans;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int H, W, K;
	cin >> H >> W >> K;

	string S[300];
	rep(i, H) cin >> S[i];

	int kara[300] = {};
	int hajimete = 500;
	rep(i, H) {
		int aru = 0;
		rep(j, W) if (S[i][j] == '#') aru = 1;
		if (!aru) kara[i] = 1;
		if (aru && hajimete == 500) hajimete = i;
	}

	int k = 0;
	int kotae[300][300];
	rep(i, H) {
		if (!kara[i]) {
			k++;
			int aru = 0;
			rep(j, W) {
				if (S[i][j] == '#') {
					if (aru == 0) aru = 1;
					else k++;
				}
				kotae[i][j] = k;
			}
		}
		else if (hajimete < i) {
			rep(j, W) kotae[i][j] = kotae[i - 1][j];
		}
	}
	for (int i = H - 1; i >= 0; i--) {
		if (kara[i] && hajimete > i) {
			rep(j, W) kotae[i][j] = kotae[i + 1][j];
		}
	}

	rep(i, H) rep(j, W) {
		if (j == W - 1) co(kotae[i][j]);
		else cosp(kotae[i][j]);
	}


	Would you please return 0;
}

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

using namespace std;
#define ll long long int

int main()
{
   ll t;
   t = 1;	
   //cin t;
   while(t--){
         ll x , n;
         cin >> x >> n;
         ll a[n];
         ll count[103] = {0};
         for(int i = 0; i < n ; i ++)
         {
             cin >> a[i];
             count[a[i]]++;
         }    
         int diff = INT_MAX;
         int ans = -1;
         for(int i = 0; i<= 102; i ++)
         {
             if(!count[i])
             {
                 if(diff > abs( i -x))
                 {
                     diff= abs(i - x);
                     ans = i;
                 }
             }
         }
         cout << ans << endl;

   }
}


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

bool dp[5001][5001];

int n,k;
int a[5001];

int ans;
int t;

int main(){

    cin >> n >> k;

    ans = n;
    t = 0;

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

    sort(a,a+n);

    for(int i=n-1; i!=-1; i--){
        if(t+a[i] < k){
            t += a[i];
        }
        else{
            ans = min(ans,i);
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <string.h>
#include <iostream>
using namespace std;

typedef pair<int,int> P;

int w,h,n;

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

int x1[1003],x2[1003],y1[1003],y2[1003];

bool fid[6003][6003];

int compress(int *X1,int *X2,int W){
  vector<int> xs;
  
  for(int i = 0;i < n;i++){
    for(int d = -1;d <= 1;d++){
      int tx1 = X1[i] + d,tx2 = X2[i] + d;
      if(0 <= tx1 && tx1 <= W) xs.push_back(tx1);
      if(0 <= tx2 && tx2 <= W) xs.push_back(tx2);
    }
  }
  
  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());
  
  for(int i = 0;i < n;i++){
    X1[i] = find(xs.begin(),xs.end(),X1[i]) - xs.begin();
    X2[i] = find(xs.begin(),xs.end(),X2[i]) - xs.begin();
  }
  
  return (int)xs.size()-1;
}

int main(){
  
  while(1){

  scanf("%d%d",&w,&h);
  
  if(w == 0)break;
  scanf("%d",&n);
  w *= 2;
  h *= 2;
  for(int i = 0;i < n;i++){
    scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
    x1[i]*=2;x2[i]*=2;y1[i]*=2;y2[i]*=2; 
  }
  
  w = compress(x1,x2,w);
  h = compress(y1,y2,h);
  
  memset(fid,0,sizeof(fid));
  
  for(int i = 0;i < n;i++){
    for(int y = y1[i];y <= y2[i];y++){
      for(int x = x1[i];x <= x2[i];x++){
	fid[y][x] = true;
      }
    }
  }
  
  int ans = 0;
  
  for(int y = 0;y <= h;y++){
    for(int x = 0;x <= w;x++){
      if(fid[y][x])continue;
      ans++;
      
      queue<P> que;
      que.push(P(x,y));
      while(que.size()){
	int nx = que.front().first,ny = que.front().second;
	que.pop();
	
	for(int i = 0;i < 4;i++){
	  int nnx = nx + dx[i];
	  int nny = ny + dy[i];
	  if(nny < 0 || nnx < 0 || nnx > w || nny > h)continue;
	  if(fid[nny][nnx])continue;
	  que.push(P(nnx,nny));
	  fid[nny][nnx] = true;
	}
      }
    }
  }
  

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


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

int main() {
  int N, M;
  cin >> N >> M;
  int H[N];
  rep(i, N) cin >> H[i];
  int A[M], B[M];
  rep(i, M) cin >> A[i] >> B[i];

  bool flag[N] = {};
  rep(i, M) {
    if(H[A[i]-1] == H[B[i]-1]) {
      flag[A[i]-1] = true;
      flag[B[i]-1] = true;
    } else if (H[A[i]-1] > H[B[i]-1]) {
      flag[B[i]-1] = true;
    } else {
      flag[A[i]-1] = true;
    }
  }
  int ans = 0;
  rep(i, N) if(!flag[i]) ans++;

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

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

//	long long dp[2000][2000] = {};
int main(){
//	string t,b;
//	cin >> t >> b;
//	dp[0][0] = 1LL;
//
//	for(int i=0; i<t.size(); i++){
//		for(int j=0; j<b.size(); j++){
//			dp[i+1][j] += dp[i][j];
//			if(t[i] == b[j]){
//				dp[i+1][j+1] += dp[i][j];
//			}
//			dp[i+1][j] %= 1000000007;
//			dp[i+1][j+1] %= 1000000007;
//		}
//		dp[i+1][b.size()] += dp[i][b.size()];
//	}
//
//	cout << dp[t.size()][b.size()]%1000000007 << endl;
//
//	return 0;
/*	int p, m, c;
	cin >> p >> m >> c;

	cout << p + m + c << endl;*/
	int ha, hb, ka, kb, a, b, c, d, x, y;
	cin >> ha >> hb >> ka >> kb >> a >>b >>c >>d;

	x = ha*a+hb*b+(ha/10)*c+(hb/20)*d;
	y = ka*a+kb*b+(ka/10)*c+(kb/20)*d;

	if(x > y){
		cout << "hiroshi" << endl;
	}

	else if(y > x){
		cout << "kenjiro" << endl;
	}

	else{
		cout << "even" << endl;
	}

	
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;

constexpr int MOD = 1e9+7;

namespace math { namespace integer {

template<class T> T mod_mul(T x, T k, T m) { if(k == 0) { return 0; } if(k % 2 == 0) { return mod_mul((x + x) % m, k / 2, m); } else { return (x + mod_mul(x, k - 1, m)) % m; } }
template<class T> T mod_pow(T x, T n, T mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
template<class T> T extgcd(T a, T b, T& x, T& y) { T d = a; if(b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x;} else { x = 1, y = 0; } return d; }
template<class T> T mod_inverse(T x, T mod) { return mod_pow(x, T(mod - 2), mod); /* use fermat */ }
template<class T> T mod_inverse_composite_num_mod(T a, ll mod) { T x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; }

}}
using namespace math::integer;

typedef long long ll;
int const inf = INT_MAX / 2;

namespace sort_algorithm {  // not verified

long long inversion_count(int n, vector<int> const& a) {
  long long ret = 0;
  rep(i, n) REP(j, i + 1, n) {
    ret += a[i] > a[j];
  }
  return ret;
}

}

int main() {
  ll N, K; cin >> N >> K;
  vector<int> A(N); rep(i, N) cin >> A[i];
  // X: A 上の転倒数
  // Y_i: A_i -> A で転倒数
  // X * K + Σ_{l=0}^{N-1} Y_i * (Σ_{k=1}^{K-1} k)

  ll ans = (sort_algorithm::inversion_count(N, A) * K) % MOD;

  rep(i, N) {
    vector<int> B;
    ll Y = 0;
    rep(j, N) Y += A[i] > A[j];
    ll p = ((K - 1) * K / 2) % MOD;
    (ans += (Y * p) % MOD) %= MOD;
  }

  cout << ans << endl;
}


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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	cout<<n+n*n+n*n*n<<"\n" ;
	return 0 ;
}		

Measured memory_bytes: 3640
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
MOD = 10**9+7

is_safe = [True]*(N+1)
for a in A:
    is_safe[a] = False

dp = [0]*(N+1)
# 初期条件
dp[0] = 1
if is_safe[1]:
    dp[1] = 1

for i in range(2, N+1):
    if is_safe[i-1]:
        dp[i] += dp[i-1]
    if is_safe[i-2]:
        dp[i] += dp[i-2]
    dp[i] %= MOD

print(dp[N])


Measured memory_bytes: 50904
// ITP1_8_D

#include<iostream>
#include<string>
using namespace std;

int main(){
  string s, p;
  bool res = true;
  cin >> s >> p;

  for (int i=0;i<s.size();i++) {
    res = true;
    for (int j=0;j<p.size();j++)
      if (s[(i + j) % s.size()] != p[j])
        res = false;
    if (res)
      break;
  }

  if (res)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



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

int n,ma,mb;
int a[40],b[40],c[40];
map<pair<int,int>,int> min_cost;

void res(int cur,pair<int,int> m,int used[]){
    //for(int i=0; i<n; i++)cout<<used[i]<<' ';cout<<endl;
    //cout<<cur<<endl;
    if(min_cost[m]==0){
        min_cost[m]=cur;
        //cout<<'a'<<endl;
    }
    else if(min_cost[m]>cur){
        min_cost[m]=cur;
    }else{
        //cout<<'b'<<endl;
        return;
    }
    for(int i=0; i<n; i++){
        if(!used[i]){
            used[i]=true;
            res(cur+c[i],make_pair(m.first+a[i],m.second+b[i]),used);
            used[i]=false;
        }
    }
}

int main(){
    cin>>n>>ma>>mb;
    int used[n];for(int i=0; i<n; i++)used[i]=0;
    for(int i=0; i<n; i++){
        int in1,in2,in3;
        cin>>in1>>in2>>in3;
        a[i]=in1;b[i]=in2;c[i]=in3;
    }
    res(0,make_pair(0,0),used);

    bool flag=true;
    long long mini=(1<<21);
    for(int i=1; i<401; i++){
        if(min_cost[make_pair(ma*i,mb*i)]!=0&&mini>min_cost[make_pair(ma*i,mb*i)]){
            flag=false;
            mini=min_cost[make_pair(ma*i,mb*i)];
        }
    }
    if(flag){
        cout<<-1<<endl;
    }else{
        cout<<mini<<endl;
    }
    cout<<endl;
    /*for(int i=1; i<401; i++){
        for(int j=1; j<401; j++)
            if(min_cost[make_pair(i,j)]!=0){
                flag=false;
                cout<<min_cost[make_pair(i,j)]<<endl;
                break;
            }
    }*/
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path; vl A(Q), B(Q), C(Q), D(Q);
vl bitList(ll n, ll k, ll f) {
	vl bitList(k);
	for (ll i = 0; i < k; i++) {
		bitList[i] = f % n;
		f /= n;
	}
	return bitList;
}
void solve2(vl X) {
	ll pre = 0;
	//debug(X);
	if (X.size() == N) {
		for (j = 0; j < Q; j++) {
			if (X[B[j] - 1] - X[A[j] - 1] == C[j]) pre += D[j];
		}
		ans = max(ans, pre);
	}
}
void solve(ll now ,ll depth,vl A) {
	if (depth == N) {
		solve2(A);
	}
	else {
		for (ll i = now; i <= M; i++) {
			vl B = A;
			B.push_back(i);
			solve(i, depth + 1, B);
		}
	}
}
int main() {
	cin >> N >> M >> Q;
	A.resize(Q);
	B.resize(Q);
	C.resize(Q);
	D.resize(Q);
	for (k = 0; k < Q; k++) {
		cin >> A[k] >> B[k] >> C[k] >> D[k];

	}
	vl A = {};
	solve(1, 0, A);
	cout << ans;
}

Measured memory_bytes: 3640
#![allow(unused_macros)]

macro_rules! line {
    () => {{
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf
    }};
}
macro_rules! line_as_vec {
    ( $t:ty ) => {
        ln!()
            .trim()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect::<Vec<$t>>()
    };
}
macro_rules! input {
    { $( $i:ident : $t:ty ),* } => {
        let ( $( $i ),* ) = match &line!().split_whitespace().collect::<Vec<_>>()[..] {
            &[ $( $i ),* ] => ( $( $i.parse::<$t>().unwrap() ),* ),
            _ => panic!(),
        };
    };
}
fn main() {
    input! {a: u64, b: u64, n: u64};

    println!(
        "{}",
        if n >= b {
            (a * (b - 1)) / b + a * ((b - 1) / b)
        } else {
            (a * n) / b + a * (n / b)
        }
    );
}


Measured memory_bytes: 2160
#include <iostream>
#include <cstdio>
#include <cmath>
int main(){
	double r,s,l;
    std::cin >> r;
	s=M_PI*r*r;
	l=2*M_PI*r;

    printf("%5lf %5lf\n",s,l);
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 50 + 5;
const int MAX_LOG_N = 7;
const int MAX_M = 20 + 5;

int n, m;
int u, v;
int fa[MAX_N][MAX_LOG_N];
int depth[MAX_N];
bool vis[MAX_N];

struct Edge {
    int to, next;
}edges[2*MAX_N];
int cnt = 0;
int head[MAX_N];

void add(int u, int v)
{
    edges[++cnt].to = v;
    edges[cnt].next = head[u];
    head[u] = cnt;
}

struct Consraints {
    int u, v, lca;
}cons[MAX_M];

void dfs(int u, int p, int d)
{
    fa[u][0] = p;
    depth[u] = d;
    for (int j = head[u]; j != -1; j = edges[j].next)
    {
        Edge& e = edges[j];
        if (e.to != p) dfs(e.to, u, d+1);
    }
}

void init(int V)
{
    dfs(1, -1, 0);
    for (int k = 0; k+1 < MAX_LOG_N; k++)
    {
        for (int v = 1; v <= V; v++)
        {
            if (fa[v][k] < 0) fa[v][k+1] = -1;
            else fa[v][k+1] = fa[fa[v][k]][k];
        }
    }
}

int lca(int u, int v)
{
    if (depth[u] < depth[v]) swap(u, v);
    for (int k = 0; k < MAX_LOG_N; k++)
    {
        if ((depth[u]-depth[v]) >> k & 1)
        {
            u = fa[u][k];
        }
    }
    if (u == v) return u;
    for (int k = MAX_LOG_N-1; k >= 0; k--)
    {
        if (fa[u][k] != fa[v][k])
        {
            u = fa[u][k];
            v = fa[v][k];
        }
    }
    return fa[u][0];
}

int main()
{
    scanf("%d", &n);
    memset(head, -1, sizeof(head));
    for (int i = 1; i < n; i++)
    {
        scanf("%d %d", &u, &v);
        add(u, v);
        add(v, u);
    }
    init(n);
//    for (int i = 1; i <= 3; i++) printf("%d %d %d %d\n", fa[i][0], fa[i][1], fa[i][2], depth[i]);

    scanf("%d", &m);
    for (int i = 0; i < m; i++)
    {
        scanf("%d %d", &u, &v);
        cons[i].u = u;
        cons[i].v = v;
        cons[i].lca = lca(u, v);
//        printf("%d %d %d\n", u, v, lca(u,v));
    }
    long long ans = 0;
    for (int S = 0; S < (1<<m); S++)
    {
        memset(vis, 0, sizeof(vis));
        int cnt = 0;
        for (int k = 0; k < m; k++)
        {
            if (S & (1<<k))
            {
                int a = cons[k].u, b = cons[k].v, l = cons[k].lca;
                while (a != l)
                {
                    if (!vis[a])
                    {
                        cnt++;
                        vis[a] = 1;
                    }
                    a = fa[a][0];
                }
                while (b != l)
                {
                    if (!vis[b])
                    {
                        cnt++;
                        vis[b] = 1;
                    }
                    b = fa[b][0];
                }
            }
        }
        long long sgn = (__builtin_popcount(S)%2 == 0 ? 1LL : -1LL);
        ans += sgn*(1LL<<(n-1-cnt));
//        printf("#%lld\n", ans);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int h,n,ans=0;
    cin>>h>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        ans+=arr[i];
    }
    if(ans>=h)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;

    return  0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 1; i < n; i++) {
        int cut = n - i + 1;
        string a = s.substr(0, i);
        string b = s.substr(i, cut);
        set <char> s;
        for (char c : a) {
            s.insert(c);
        }
        int res = 0;
        sort(b.begin(), b.end());
        b.resize(unique(b.begin(), b.end()) - b.begin());
        for (char c : b) {
            if (s.count(c)) {
                res++;
            }
        }
        ans = max(ans, res);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
x,y,a,b,c = list(map(int,input().split()));
p = list(map(int,input().split()));
q = list(map(int,input().split()));
r = list(map(int,input().split()));

umami = [[0]*2 for i in range(a+b+c)];
um = [0]*(x+y+c);

for i in range(a) :
    umami[i][0] = 0;
    umami[i][1] = p[i];

for i in range(b) :
    umami[a+i][0] = 1;
    umami[a+i][1] = q[i];
for i in range(c) :
    umami[a+b+i][0] = 2;
    umami[a+b+i][1] = r[i];

p.sort();
p.reverse();
q.sort();
q.reverse();
r.sort();
r.reverse();
for i in range(x) :
    um[i] = p[i];
for i in range(y) :
    um[i+x] = q[i];
for i in range(c) :
    um[i+x+y] = r[i];

um.sort();
um.reverse();

umami.sort(key=lambda x:x[1]);
umami.reverse();
i = 0;
j = 0;
numr = x;
numg = y;
ans = 0;

while i < x+y :
    if umami[j][0] == 0 and numr == 0 :
        j += 1;
    if umami[j][0] == 1 and numg == 0 :
        j += 1;
    else :
        if umami[j][0] == 0 :
            numr -= 1;
        if umami[j][0] == 1 :
            numg -= 1;
        ans += umami[j][1];
        i += 1;
        j += 1;

ans = 0;
for i in range(x+y) :
    ans += um[i];

print(ans);

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll a, b;
    cin >> a >> b;

    REP(n, 100) {
        if(n*(a-1)+1 >= b) {
            cout << n << endl;
            return 0;
        }
    }

    return 0;
}


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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e9

int col[100005];

int main ()
{
    int n; cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int x; cin >> x;
        col[x] = i;
    }

    for (int i = 1; i <= n; i++)
        cout << col[i] << " ";

    cout << endl;

    return 0;
}


Measured memory_bytes: 1152
while True:
    h, w = map(int, raw_input().split())
    if w == 0 and h == 0:
        break
    tile = []
    for i in range(h):
        tile.append(list(raw_input()))
    x = y = 0
    while True:
        a = tile[y][x]
        tile[y][x] = 0
        if   a == ">": x += 1
        elif a == "<": x -= 1
        elif a == "^": y -= 1
        elif a == "v": y += 1
        elif a == ".": print x,y; break
        else: print "LOOP"; break

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

#include <atcoder/fenwicktree.hpp>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll n, q;
    cin >> n >> q;
    atcoder::fenwick_tree<ll> ft(n);

    rep(i, n) {
        ll a;
        cin >> a;
        ft.add(i, a);
    }

    rep(i, q) {
        ll t, a, b;
        cin >> t >> a >> b;
        if (t == 0) ft.add(a, b);
        else
            cout << ft.sum(a, b) << "\n";
    }
    return 0;
}

Measured memory_bytes: 8252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    public static void main(String[] args) throws IOException {
//    	long l = System.currentTimeMillis();
        new Main().exec();
//    	long l2 = System.currentTimeMillis();
//    	System.out.println(l2 - l);
    }
    
    public void exec() throws IOException {
        InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int N = in.nextInt();
        out.println("ABC"+N);
        out.flush();
    }
    
}

class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 50000;
	
	//Fields
	protected InputStream in;
	private char[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private BufferedReader br = null;
	
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {br = new BufferedReader(new InputStreamReader(this.in = in));}
	protected void initBuf(int bufsiz) {buf = new char[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && br.ready()) {
			max = br.read(buf);
			ptr = 0;
		}
	}
	//Number Input Reader/Parser
	private boolean isNum(char b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(char b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		char c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

}

Measured memory_bytes: 21332
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        while(!(x == 0 && y == 0)){
            if(x < y){
                System.out.println(x+" "+y);
            }else{
                System.out.println(y+" "+x);
            }
            x = scan.nextInt();
            y = scan.nextInt();
        }
    }
}


Measured memory_bytes: 35900