akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

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

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var jobs = new Tuple<int, int>[N];
            for (int i = 0; i < N; i++)
            {
                jobs[i] = new Tuple<int, int>(cin.ReadInt, cin.ReadInt);
            }
            jobs = jobs.OrderBy(j => j.Item2).ToArray();

            var t = 0L;
            foreach (var job in jobs)
            {
                t += job.Item1;
                if (t > job.Item2)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");
        }
    }

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


Measured memory_bytes: 34084
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  int P[M],Y[M];
  vector<int> vec[N+1];
  for(int i=0;i<M;i++){
    cin >> P[i] >> Y[i];
    vec[P[i]].push_back(Y[i]);
  }
  for(int i=1;i<=N;i++){
    sort(vec[i].begin(),vec[i].end());
  }
  for(int i=0;i<M;i++){
    printf("%06d",P[i]);
    int temp;
    temp=lower_bound(vec[P[i]].begin(),vec[P[i]].end(),Y[i])-vec[P[i]].begin()+1;
    printf("%06d\n",temp);
  }

  return 0;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
int main(){
    long long a,b,n;
    cin>>a>>b>>n;
    long long x;
    x=b-1;
    if (n<x){
        x=n;
    }
    long long ans=(a*(x%b))/b;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3580
def main():
  from collections import defaultdict
  from collections import Counter
  
  n = int(input())
  a = list(map(int, input().split()))
  
  d = Counter(a)
  e = defaultdict(int)
  
  func = lambda x: x*(x-1)//2 if x>=2 else 0
  v = list(d.values())
  base = sum(list(map(func, v)))
  
  for k,v in d.items():
    if v<=1:
      e[k] = base - 0
    else:
      e[k] = base - ( v*(v-1)//2 - (v-1)*(v-2)//2 )
    
  p = [str(e[x])+'\n' for x in a]
  q = ''.join(p)
  print(q)
      
 
if __name__=='__main__':
    main()


Measured memory_bytes: 46080
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if(N==1) {
			System.out.println(1);
			return ;
		}
		Main main = new Main();
		long x[]= new long[N];
		long y[] = new long[N];
		for (int i=0;i<N;i++) {
			x[i] = sc.nextLong();
			y[i] = sc.nextLong();
		}
		int max =1;
		Map<Point,Integer> map = new HashMap<Point,Integer>();
		for (int i=0;i<N;i++) {
			for (int j=0;j<N;j++) {
				if (i!=j) {
					Point t = main.new Point();
					t.p=x[j]-x[i];
					t.q=y[j]-y[i];
					if (map.containsKey(t)==false) {
						map.put(t, 1);
					} else {
						Integer in = map.get(t);
						map.put(t, in+1);
						if (in +1>=max) {
							max = in +1;
						}
					}
				}

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

	public class Point extends Object{
		long p;
		long q;

		@Override
		public boolean equals(Object o) {
			Point p = (Point)o;
			if (p.p==this.p&&p.q==this.q) {
				return true;
			}
			return false;
		}

		@Override
		public int hashCode() {
			return (int)(this.p%1000000+this.q%1000000);
		}

	}

}

Measured memory_bytes: 37028
N = int(input())
count = 0
total = 0
H = []
s = input().split()

for i in range(N):
  H.append(int(s[i]))
  for j in range(i):
    if(H[i] >= H[j]):
      count = count + 1
  if(count == i):
    count = 0
    total = total + 1
  count = 0
    
print(total)

Measured memory_bytes: 3064
import std.stdio, std.string, std.algorithm, std.conv, std.array;

void main() {
  int n; readf("%d\n", &n);
  for(int t = 0; t < n; t++) {
    int[10][10] w1, w2;
    int[10][3][3] w3;
    int[9][9] field;
    for(int i = 0; i < 9; i++)
      for(int j = 0; j < 9; j++)
        readf(j == 8 ? "%d\n" : "%d ", &field[i][j]);
    
    for(int i = 0; i < 9; i++)
      for(int j = 0; j < 9; j++) {
        w1[i][field[i][j]]++;
        w2[j][field[i][j]]++;
        w3[i / 3][j / 3][field[i][j]]++;
      }
    
    for(int i = 0; i < 9; i++)
      for(int j = 0; j < 9; j++) {
        writef("%s%d%s",
               (w1[i][field[i][j]] != 1 ||
                w2[j][field[i][j]] != 1 ||
                w3[i / 3][j / 3][field[i][j]] != 1) ? "*" : " ",
          field[i][j], j == 8 ? "\n" : "");
      }
    
    if (t != (n - 1)) writeln;
  }
}

Measured memory_bytes: 1092
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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


class UnionFind
{
	//par[i]：ノードiの親
	//count[i]：iが親の時、iが属するグループのノード数
	vector<int> par;
	vector<int> count;

	int m_groupCount = 0;

public:
	UnionFind(int N)
	{
		m_groupCount = N;

		for (int i = 0; i < N; i++)
		{
			//最初は全てが根であるとして初期化
			par.push_back(i);
			count.push_back(1);
		}
	}

	//データxが属する木の根を再帰で得る：root(x) = {xの木の根}
	int root(int x)
	{
		if (par[x] == x) return x;

		//ついでに親を張り替え
		return par[x] = root(par[x]);
	}

	//xとyの木を併合
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return;
		//xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		par[rx] = ry;

		//要素数の変更
		count[ry] += count[rx];
		count[rx] = 0;

		//木の併合によってグループが1つ減る
		m_groupCount--;
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y)
	{
		return root(x) == root(y);
	}

	//指定したデータxが属するグループの要素数を返す
	int size(int x)
	{
		return count[root(x)];
	}

	//UnionFindのグループの個数を返す
	int groupCount()
	{
		return m_groupCount;
	}
};


int main()
{	
	int N, M;
	cin >> N >> M;

	vector<pair<int, int>> E(M);

	rep(i, M)
	{
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		E[i].first = a;
		E[i].second = b;
	}

	ll count = 0;

	rep(i, M)
	{
		UnionFind uf(N);

		rep(j, M)
		{
			if (j == i) continue;

			uf.unite(E[j].first, E[j].second);
		}

		if (uf.groupCount() != 1) count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    if(n == 3){
        cout << "2 5 63" << endl;
    }
    else if(n == 4){
        cout << "2 5 20 63" << endl;
    }
    else if(n == 5){
        cout << "2 4 6 3 9" << endl;
    }
    else if(n == 6){
        cout << "2 4 6 3 9 30" << endl;
    }
    else{
        int k = 0;
        int m = 0;
        while(n >3){
            if(6*k + 6 < 6*m + 9){
                cout << 6 * k + 2 << " " << 6 * k + 4 << " " << 6 * k + 6 << " ";
                k += 1;
                n -= 3;
            }
            else{
                cout << 6 * m + 3 << " " << 6 * m + 9 <<" ";
                m += 2;
                n -= 2;
            }

        }
        if(n == 1){
            cout << 6 * (k+1) << endl;
        }
        else if(n == 3){
                cout << 6 * k + 2 << " " << 6 * k + 4 << " " << 6 * k + 6 << endl;            
        }
        else if(n == 2){
            cout << 6 * k + 2 << " " << 6 * k + 4 << endl;
        }
    }

}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
vector <int> n;

int main(){
	string s;
	cin>>s;
	if(s[1]=='B'){
		cout<<"ARC"<<endl;
	}else{
		cout<<"ABC"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    int ans = 0;
    ans += min(k,n) * x;
    ans += max(0,n-k) * y;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
import sys
import bisect
from collections import deque
input = sys.stdin.readline
n = int(input().strip())
q = deque()
qappL = q.appendleft
for i in range(n):
  a = int(input().strip())
  b = bisect.bisect_left(q,a)
  if b == 0:
    qappL(a)
  else:
    q[b-1] = a
print(len(q))

Measured memory_bytes: 7284
open System

let a, b, h, m =
    let l = Console.ReadLine().Split(' ') |> Array.map float
    l.[0], l.[1], l.[2], l.[3]

let l =
    let theta =
        let pi = Math.PI
        let t1 =
            let h = (int h) % 12 |> float
            ((60.0 * h + m) / (12.0 * 60.0)) * 2.0 * pi
        let t2 =
            (m / 60.0) * 2.0 * pi
        Math.Abs (t1 - t2)

    a * a + b * b - 2.0 * a * b * (Math.Cos theta)
    |> Math.Sqrt

l |> Console.WriteLine


Measured memory_bytes: 28268
import java.io.*;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = in.nextInt();
        int m = in.nextInt();
        int[] del = new int[n + 1];
        for (int i=0; i<m; i++) {
            int l = in.nextInt();
            int r = in.nextInt();
            del[l - 1]++;
            del[r]--;
        }
        int[] res = new int[n];
        res[0] = del[0];
        for (int i=1; i<n; i++) {
            res[i] = res[i - 1] + del[i];
        }
        int c = 0;
        for (int i=0; i<n; i++) {
            if (res[i] == m) {
                c++;
            }
        }
        out.println(c);
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

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

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

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public double[] nextDoubleArray(int n) {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextDouble();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        public char[] nextCharArray(int n) {
            char[] arr = nextLine().trim().replaceAll("\\s", "").toCharArray();
            return arr;
        }

        public String[] nextStringArray(int n) {
            String[] arr = new String[n];
            for (int i = 0; i < n; i++) {
                arr[i] = next();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 38780
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define F first
#define s second
#define int long long		
int x[214514];
string y[214514];
char z[214514];
int sum[214514];
signed main(){
	sc(s)
	int n=s.size();
	int sum=0;
	rep(0,i,n){
		if(i%2==0){
			if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
				sum++;
			}	
		}
		else{
			if(s[i]=='L'||s[i]=='U'||s[i]=='D'){					
				sum++;
			}
		}
	}
	if(sum==n)c("Yes")
	else c("No")
}				

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

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

std::istream &operator>>(std::istream &is, P &p){
	return is >> p.first >> p.second;
}

struct Dice{
private:
	static const int _roll[4][6], _turn[2][6];
public:
	vector<int> value;
	// 1-6 : top, near, right, left, far, bottom 

	Dice(){
		value.resize(6);
		for (int i = 0; i < 6; ++i) value[i] = i+1;
	}
	Dice(initializer_list<int> il){
		value.resize(6, -1);
		int cnt = 0;
		for (auto &e : il){
			value[cnt++] = e;
			if (cnt >= 6) break;
		}
		for (int i = 0; i < 6; ++i) if (value[i] < 0) value[i] = 5 - value[5 - i];
	}

	void roll(int dir){ // N, E, W, S
		vector<int> nxt(6);
		for (int i = 0; i < 6; ++i){
			nxt[i] = value[_roll[dir][i]];
		}
		value = nxt;
	}

	void turn(int dir){ // L, R
		vector<int> nxt(6);
		for (int i = 0; i < 6; ++i){
			nxt[i] = value[_turn[dir][i]];
		}
		value = nxt;
	}

	int &operator[](int i){
		return value[i];
	}
};

const int Dice::_roll[4][6] = {
	{ 1, 5, 2, 3, 0, 4 }, // North
	{ 3, 1, 0, 5, 4, 2 }, // East
	{ 2, 1, 5, 0, 4, 3 }, // West
	{ 4, 0, 2, 3, 5, 1 }, // South
};

const int Dice::_turn[2][6] = {
	{ 0, 3, 1, 4, 2, 5 }, // Left
	{ 0, 2, 4, 1, 3, 5 }, // Right
};

int board[10][10];

struct state{
	P first;
	Dice second;
	bool operator<(const state &r)const{
		if(first != r.first) return first < r.first;
		rep(i, 6) if (second.value[i] != r.second.value[i]) return second.value[i] < r.second.value[i];
		return false;
	}
};

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

int main(){
	int h, w;
	while (cin >> h >> w, h | w){
		rep(i, h) rep(j, w) cin >> board[i][j];
		P s, g;
		cin >> s >> g;

		map<state, int> m;

		priority_queue<pair<int, state>, vector<pair<int, state>>, greater<pair<int, state>>> q;
		q.push(make_pair(0, state{ s, Dice() }));
		int ans = -1;
		while (!q.empty()){
			int dist = q.top().first;
			state s = q.top().second;
			P &pos = s.first;
			Dice &d = s.second;
			q.pop();
			
			if (m[s] < dist) continue;
			if (s.first == g){
				ans = dist;
				break;
			}

			rep(i, 4){
				int nx = pos.second + dx[i], ny = pos.first + dy[i];
				if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
				state nxt = s;
				nxt.second.roll(i);
				nxt.first = make_pair(ny, nx);
				if (m.count(nxt) && m[nxt] <= dist + nxt.second[5] * board[ny][nx]) continue;
				m[nxt] = dist + nxt.second[5] * board[ny][nx];
				q.push(make_pair(dist + nxt.second[5] * board[ny][nx], nxt));
			}
		}
		//cout << "+++";
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1392
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
int main(){
    int a,b;
    std::cin >> a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0)std::cout << "Possible" << std::endl;
    else std::cout << "Impossible" << std::endl;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n){
        cin >> a[i];
    }
    multiset<int> tmp;
    int cnt = 0;
    REP(i, n){
        auto pos = tmp.lower_bound(a[i]);
        if(pos == tmp.begin()){
            cnt++;
            tmp.insert(a[i]);
        }
        else{
            pos--;
            tmp.erase(pos);
            tmp.insert(a[i]);
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 5376
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N;
ll A[212345];

int main() {

	scanf("%lld", &N);
	rep(i,N) scanf("%lld", &A[i]);

	ll L = 0;
	rep(i, N) L += A[i];
	ll sub = 0;
	ll ans = 0;
	rep(i, N) {
		sub += A[i];
		if (sub >= L/2) {
			ans += min(abs(L -sub - sub), abs(L - (sub - A[i]) - (sub - A[i])));
			break;
		}
	}

	printf("%d\n", ans);

	return 0;
}

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

public class Main
{
   public static void main(String[] args)
   {
      try {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         String s;
         while((s=br.readLine())!=null){
            StringTokenizer st=new StringTokenizer(s, " ");
            int a=Integer.parseInt(st.nextToken());
            int b=Integer.parseInt(st.nextToken());
            a+=b;
            int keta=1;
            while((a/=10)!=0) keta++;
            System.out.println(keta);
         }
      } catch(Exception e){}
   }
}

Measured memory_bytes: 10000
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
typedef vector<int> vi;
#define FOR(i,S,E) for(int i=S; i<E; i++)
#define ri(x) scanf("%d", &x)
#define pb push_back

const int MAXN = 8e3+10;
char s[MAXN];
int x, y, n, dp[2*MAXN][MAXN];

int fx(int i=0, int idx=0) {
    //printf("fx(%d, %d)\n", i, idx);
    if (idx >= n && i == x) return true;
    else if (idx >= n) return false;
    if (dp[i+n][idx] != -1) return dp[i+n][idx];
    int steps = 0, k;
    for(k=idx; k<n && s[k] != 'T'; k++) {
        continue;
    }
    steps = k-idx;
    for(k = k+1 ; k<n && s[k] != 'T'; k++) {
        continue;
    }
    dp[i+n][idx] = fx(i+steps, k+1);
    if (idx)
        dp[i+n][idx] |= fx(i-steps, k+1);
    return dp[i+n][idx];
}

int fy(int j=0, int idx=0) {
    //printf("fy(%d, %d)\n", j, idx);
    if (idx >= n && j == y) return true;
    else if (idx >= n) return false;
    if (dp[j+n][idx] != -1) return dp[j+n][idx];
    int steps = 0, k;
    for(k=idx; k<n && s[k] != 'T'; k++) {
        continue;
    }
    steps = k-idx;
    for(k = k+1 ; k<n && s[k] != 'T'; k++) {
        continue;
    }
    return dp[j+n][idx] = fy(j+steps, k+1) || fy(j-steps, k+1);
}

int main() {
    scanf("%s", s);

    n = strlen(s);
    scanf("%d%d", &x, &y);
    //printf("n: %d\n", n);
    FOR(i,0,2*n) FOR(j,0,n) dp[i][j] = -1;
    int ans = fx();
    //cout << ans << endl;
    int k;
    for(k=0; k<n && s[k] != 'T'; k++) {
        continue;
    }
    FOR(i,0,2*n) FOR(j,0,n) dp[i][j] = -1;
    ans &= fy(0, k+1);
    if (ans) printf("Yes\n");
    else printf("No\n");
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{

    while (1)
    {
        int sum = 0;
        string s;
        cin >> s;
        if (s == "0")
        {
            break;
        }

        rep(i, s.length())
        {
            sum += (int)s[i] - (int)'0';
        }

        OP(sum)
    }
    return 0;
}


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

bool check(int arr[],int k){
	
  	for(int i=0;i<5;i++){
    	for(int j=i+1;j<5;j++){
        	if(arr[j]-arr[i]>k) return 0;
        }
    }
  return 1;
}

int main(){
	
  	int arr[5];
  	int k;
  	for(int i=0;i<5;i++) cin>>arr[i];
    cin>>k;
  	if(!check(arr,k)) cout<<":("<<endl;
	else cout<<"Yay!"<<endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BTwoAnagrams {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string s, t;
	    in >> s >> t;

        sort(s.begin(), s.end());
        sort(t.begin(), t.end(), greater<char>());
        ans(s < t, out);
	}
};


int main() {
	BTwoAnagrams solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

typedef long long ll;

string S, T;

int N, M;

int gcd(int a, int b)
{
	return (b == 0 ? a : gcd(b, a % b));	
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> N >> M >> S >> T;
	int x = gcd(N, M);
	int n = N / x, m = M / x;
//	cerr << "n: " << n << " m: " << m << endl;
	bool ch = 1;
	for (int i = 0, j = 0; i < N && j < M; i += n, j += m)
		ch &= (S[i] == T[j]);
	if (ch)
		cout << (ll)N * M / x << endl;
	else
		cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
using namespace std;

//メッセージ復元
string back(string s, char c){
	string t="";
	if(c=='J'){
		char t1=s[s.size()-1];
		string t2=s.substr(0, s.size()-1);
		t+=t1+t2;
	}
	else if(c=='C'){
		char t1=s[0];
		string t2=s.substr(1, s.size()-1);
		t+=t2+t1;
	}
	else if(c=='E'){
		int size=s.size();
		char mid;
		if(size%2==1) mid=s[size/2];
		
		string t1=s.substr(0, size/2);
		string t2=s.substr((size+1)/2, size/2);
		
		t+=t2;
		if(size%2==1) t+=mid;
		t+=t1;
	}
	else if(c=='A'){
		t=s;
		reverse(t.begin(), t.end());
	}
	else if(c=='P'){
		for(int i=0; i<s.size(); ++i){
			if('0'<=s[i] && s[i]<='9'){
				if(s[i]=='0') t+='9';
				else t+=s[i]-1;
			}
			else t+=s[i];
		}
	}
	else if(c=='M'){
		for(int i=0; i<s.size(); ++i){
			if('0'<=s[i] && s[i]<='9'){
				if(s[i]=='9') t+='0';
				else t+=s[i]+1;
			}
			else t+=s[i];
		}	
	}
	return t;
}

int main(){
	long n;
	scanf(" %ld", &n);
	for(long i=0; i<n; ++i){
		string o; //order of the messenger	
		string m; //message given to the king
		cin >> o >> m;
		for(int j=o.size()-1; j>=0; --j)
			m=back(m, o[j]);		
		
		cout << m <<endl;
	}
	return 0;
}

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

#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define F first
#define S second 

vector<int> v[100100];
stack<pair<int,pair<int,int> > > s;
int col[100100],le[100100];

main()
{
	int n,m,q;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		v[a].PB(b);
		v[b].PB(a);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		s.push(MP(a,MP(b,c)));
	}
	while(!s.empty())
	{
		int nw=s.top().F;
		int d=s.top().S.F;
		int c=s.top().S.S;
		s.pop();
		queue<pair<int,pair<int,int> > > q;
		if(col[nw]!=0&&le[nw]<d)
			q.push(MP(nw,MP(d,c)));
		else if(col[nw]==0)
		{
			col[nw]=c;
			q.push(MP(nw,MP(d,c)));
		}
		while(!q.empty())
		{
			int po=q.front().F;
			int lf=q.front().S.F;
			int color=q.front().S.S;
			q.pop();
			//printf("%d %d %d|",po,lf,color);
			lf--;
			if(lf<0)
			{
				continue;
			}
			//printf("%d %d %d\n",po,lf,color);
			for(int i=0;i<v[po].size();i++)
			{
				int go=v[po][i];
				if(col[go]!=0&&le[go]<lf)
				{
					q.push(MP(go,MP(lf,color)));
					le[go]=lf;
				}
				else if(col[go]==0)
				{
					q.push(MP(go,MP(lf,color)));
					col[go]=color;
				}
			}
		}
	}
	for(int i=1;i<=n;i++)printf("%d\n",col[i]);
}

Measured memory_bytes: 9384
x = int(input())
d3 = 0
d21 = 0
if x >99:
    d3 = int(str(x)[-3])
    d21 = int(str(x)[-2::])


if 1 <= x < 100:
    print(0)

elif x < 1000:
    if (d3 * 105) % 100 < d21:
        print(0)
    else:
        print(1)

elif 1000 <= x < 2000:
    if (d3 * 105) % 100 + 50 < d21:
        print(0)
    else:
        print(1)

else:
    print(1)

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
 
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans=0;
  for(int i=0;i<N;++i){
    if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C'){
      ++ans;
    }
  }
  cout << ans;
  }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

struct City {
    int id;
    int year;
    int order;
};

struct Prefecture {
    std::vector<City *> cities;
};

int main() {
    int N, M;
    std::cin >> N >> M;

    City *cities = new City[M];
    std::vector<Prefecture> prefectures(N);

    for (int i = 0; i < M; i++) {
        int id, year;
        City &city = cities[i];
        std::cin >> id >> year;
        city.id = id;
        city.year = year;
        prefectures[id - 1].cities.push_back(&city);
    }

    for (int i = 0; i < N; i++) {
        std::vector<City *> cities = prefectures[i].cities;
        std::sort(cities.begin(), cities.end(), [](City *a, City *b) -> int { return (a->year < b->year); });
        for (int j = 0; j < cities.size(); j++) {
            cities[j]->order = j + 1;
        }
    }

    char output[13]; output[12] = '\0';
    for (int i = 0; i < M; i++) {
        City &city = cities[i];
        int id = city.id;
        int order = city.order;
        sprintf(output, "%06d%06d", id, order);
        printf("%s\n", output);
    }

    return 0;
}


Measured memory_bytes: 8192
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

C = [[False] * 3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        if A[i][j] in B:
            C[i][j] = True

for i in range(3):
    if C[i][0] == C[i][1] == C[i][2] == True:
        print ('Yes')
        exit()

for i in range(3):
    if C[0][i] == C[1][i] == C[2][i] == True:
        print ('Yes')
        exit()

if C[0][0] == C[1][1] == C[2][2] == True:
    print ('Yes')
    exit()

if C[2][0] == C[1][1] == C[0][2] == True:
    print ('Yes')
    exit()

print ('No')

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    ReadStr();
    Console.WriteLine(GCD(ReadIntArray()));
  }

  public static int GCD(int[] array) {
    int res = array[0];
    for (int i = 1; i < array.Length; i++) {
      res = GCD(res, array[i]);
    }
    return res;
  }

  public static int GCD(int a, int b) {
    if (a < b) {
      Swap(ref a, ref b);
    }
    int mod = a % b, div = b, temp;
    while (mod != 0) {
      temp = mod;
      mod = div % mod;
      div = temp;
    }
    return div;
  }

  public static void Swap<T>(ref T a, ref T b) {T temp = a;a = b;b = temp;}
  public static string ReadStr() { return Console.ReadLine(); }
  public static int ReadInt() { return int.Parse(Console.ReadLine()); }
  public static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  public static long ReadLong() { return long.Parse(Console.ReadLine()); }
  public static char ReadChar() { return Console.ReadLine()[0]; }
  public static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  public static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  public static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  public static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  public static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  public static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}


Measured memory_bytes: 19680
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//define
#define i(X) cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define vll(A) vector<long lonh> A;
#define ivt(A,n,p) vector<long long> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair

const long long inf=(long long)1e18;
const long long mod=(long long)(1e9+7);

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1; 
    x = x % p;  
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll a,ll p)
{
   return power(a,p-2,p);
}

int main()
{
    // #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
    fio;
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        ll n;
        i(n);
        ll s=0;
        ll p,x,y;
        ll z[100001]={0};
        forin(i,0,n-1)
        {
            i(p);
            z[p]++;
            s+=p;
        }
        ll q;
        i(q);
        while(q--)
        {
            cin>>x>>y;
            s-=z[x]*x;
            s+=z[x]*y;
            z[y]+=z[x];
            z[x]=0;
            ol(s);
        }
    }
    return 0;
}

Measured memory_bytes: 4328
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=200005;
const double PI=acos(-1.0);
struct node{int x,y;}w[MAXN];
bool cmp(node n1,node n2){return n1.x<n2.x;}
int n,sx,sy,ex,ey;
int ls[MAXN],lslen,bi[MAXN],f[MAXN];
int lowbit(int x){return x&-x;}
void modify(int x,int c){for(;x<=lslen;x+=lowbit(x))bi[x]=max(bi[x],c);}
int qry(int x){int ret=0;for(;x>=1;x-=lowbit(x))ret=max(ret,bi[x]);return ret;}
int main()
{
	sx=read();sy=read();ex=read();ey=read();
	bool tf=false;
	if(sx>=ex)swap(sx,ex),swap(sy,ey);
	if(sy>=ey)tf=true,sy=1e8-sy,ey=1e8-ey;
	n=read();int tot=0;
	for(int i=1;i<=n;i++)
	{
		int x=read(),y=read();
		if(tf)y=1e8-y;
		if(x>=sx&&x<=ex&&y>=sy&&y<=ey)w[++tot].x=x,w[tot].y=y,ls[tot]=y;
	}sort(ls+1,ls+1+tot);lslen=tot;
	for(int i=1;i<=tot;i++)w[i].y=lower_bound(ls+1,ls+1+lslen,w[i].y)-ls;
	sort(w+1,w+1+tot,cmp);int ans=0;
	for(int i=tot;i>=1;i--)
	{
		f[i]=qry(lslen-w[i].y+1)+1;
		modify(lslen-w[i].y+1,f[i]);ans=max(ans,f[i]);
	}
	double sum=1LL*100*(ex-sx+ey-sy),dl=PI*5-20;
	if(ans==min(ey-sy+1,ex-sx+1))--ans,sum+=PI*10-20;
	sum+=dl*ans;printf("%.11lf\n",sum);
	return 0;
}


Measured memory_bytes: 4096
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 505
int n, cnt[N], X[N];
int ans[N * N];
struct Node
{
	int x, id;
}A[N];
bool cmp(Node a, Node b){return a.x < b.x;}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &X[i]);
		A[i].x = X[i];
		A[i].id = i;
	}
	sort(A + 1, A + n + 1, cmp);
	int p = 1;
	for (int i = 1; i <= n * n; i++)
	{
		if (i == A[p].x)
		{
			if (cnt[A[p].id] == A[p].id - 1)
			{
				ans[i] = A[p].id;
				cnt[A[p].id]++;
			}
			else
			{
				puts("No");
				return 0;
			}
			p++;
		}
		else
		{
			int m = n + 1;
			for (int j = 1; j <= n; j++)
				if (cnt[j] < j - 1)
					if (m == n + 1 || X[j] < X[m])
						m = j;
			if (m == n + 1)
			{
				for (int j = 1; j <= n; j++)
					if (cnt[j] >= j && cnt[j] < n)
						m = j;
				if (m == n + 1)
				{
					puts("No");
					return 0;
				}
			}
			ans[i] = m;
			cnt[m]++;
		}
	}
	puts("Yes");
	for (int i = 1; i <= n * n; i++)
		printf("%d%c", ans[i], i == n * n ? 10 : 32);
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int a,b,x;

double calc(double theta){
	if(theta > M_PI / 2.0 - EPS) {
        return 0.0;
    }
	long double ret;
	if(a * tan(theta) <= b)ret = a * a * b - a * a * a * tan(theta) / 2.0;
	else ret = b * b / tan(theta) * a / 2.0;
	return ret;
}
int main(){
	cin >> a >> b >> x;
	double left = 0; double right = M_PI/2.0;
	double mid;
 	 while(right - left > EPS) {
		mid = (left + right) / 2.0;
		// cout << left << " " <<mid << " " << right << endl;
		double volume = calc(mid);
		// cout << volume << endl;
		if(volume < x) right = mid;
		else left = mid;
		
	}      
	 cout << fixed << setprecision(10)<<right / M_PI * 180 << endl;                                                                          
}

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

using namespace std;
const int MAXN = 5005;
long long x;
int ans;
int dp[MAXN][MAXN];
int dp2[MAXN][MAXN];
int arr[MAXN];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
	    cin>>arr[i];
	}
	for(int i=0;i<=n;i++){
	    for(int j=0;j<=k;j++){
	        dp[i][j] = false;
	        dp2[i][j] = false;
	    }
	}
	dp[0][0] = true;
	for(int i=1;i<=n;i++){
	    for(int j=0;j<=k;j++){
	        dp[i][j] = dp[i-1][j];
	        if(j-arr[i]>=0){
	            if(dp[i-1][j-arr[i]]){
	                dp[i][j] = true;
	                
	            }
	        }
	    }
	}
	dp2[n+1][0] = true;
	for(int i=n;i>=1;i--){
	    for(int j=0;j<=k;j++){
	        dp2[i][j] = dp2[i+1][j];
	        if(j-arr[i]>=0){
	            if(dp2[i+1][j-arr[i]]){
	                dp2[i][j] = true;
	                
	            }
	        }
	    }
	}

	for(int i=1;i<=n;i++){
	   
	    int target = k-arr[i];
	    if(target<=0){
	        continue;
	    }
	    bool ok = true;
	    for(int j=target;j<=k-1;j++){
	        if(dp2[i+1][j]){
	            ok = false;
	            break;
	        }
	    }
	    int l = target;
	    
	    for(int j=1;j<=k-1;j++){
	        if(l){
	            l--;
	        }
	        if(dp2[i+1][l] && dp[i-1][j]){
	            
	            ok = false;break;
	        }
	    }
	    if(!ok){
	        continue;
	    }
	   
	    ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 195840
#include <stdio.h>
#include <string.h>

char flags[1000001];

int main(void) {
	int n,a,b;
	int i;
	int count;
	while(1) {
		scanf("%d%d%d",&n,&a,&b);
		if(n==0 && a==0 && b==0)break;
		memset(flags,0,sizeof(flags));
		flags[0]=1;
		for(i=1;i<=n;i++) {
			if((i>=a && flags[i-a]) || (i>=b && flags[i-b])) {
				flags[i]=1;
			}
		}
		for(i=1,count=0;i<=n;i++) {
			if(!flags[i])count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
lists = []

for i in range(N):
    lists.append(list(map(int,input().split())))

dp = [[0 for i in range(3)] for j in range(N)]
dp[0] = lists[0]
for i in range(1,N):
    for j in [0,1,2]:

        if j == 0:
            dp[i][j] = lists[i][0] + max(dp[i - 1][1], dp[i - 1][2])
        elif j == 1:
            dp[i][j] = lists[i][1] + max(dp[i - 1][0], dp[i - 1][2])
        else:
            dp[i][j] = lists[i][2] + max(dp[i - 1][0], dp[i - 1][1])

print(max(dp[N-1]))

Measured memory_bytes: 47380