akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll n,a;
    cin>>n;
    map<ll,ll> mp;
    rep(i,n){
        cin>>a;
        mp[-a]++;
    }
    ll h=0,w=0;
    for(auto x:mp){
        if(x.second>=4){
            if(h==0){
                h=w=-x.first;
                break;
            }else{
                w=-x.first;
                break;
            }
        }else if(x.second>=2){
            if(h==0) h=-x.first;
            else{
                w=-x.first;
                break;
            }
        }
    }
    cout<<h*w<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
 
#define INF (int)(1e9)
 
#define MAX_V 210
 
struct edge{ int to, cap, rev; };
 
vector<edge> G[MAX_V];
bool used[MAX_V];
 
int V, E;
 
void add_edge(int from, int to, int cap){
	G[from].push_back((edge){to,cap,(int)G[to].size()});
	G[to].push_back((edge){from, 0, (int)G[from].size()-1});
}
 
int dfs(int v, int t, int f){
	if(v == t) return f;
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to, t, min(f,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
 
int max_flow(int s, int t){
	int flow = 0;
	for(;;){
		memset(used, 0,sizeof(used));
		int f = dfs(s,t,INF);
		if(f == 0) return flow;
		flow += f;
	}
}

signed main(){
  vector<pair<int,int> > red;
  pair<int,int> blue;
  int N;

  cin>>N;

 
  red.resize(N);
 
  for(int i = 0; i < N; i++){
    cin>>red[i].first>>red[i].second;
    add_edge(0,i+1,1);
  }

  for(int i = 0; i < N; i++){
    cin>>blue.first>>blue.second;
    add_edge(N+i+1,N*2+1,1);
    for(int j = 0; j < N; j++){
      if(blue.first > red[j].first && blue.second > red[j].second){
	add_edge(j+1,N+i+1,1);
      }
    }
  }

  cout<<max_flow(0,N*2+1)<<endl;

  

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int A, B;
	int sum = 0;
	cin >> A >> B;
	int sub = B - A;
	REP(i, sub) sum += i;
	cout << sum - A << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {

	int n,m;
	int s,c;
	vector<int> sv,cv;
	cin >> n >> m;
	rep(i,m) {
		cin >> s >> c;
		sv.pb(s-1);
		cv.pb(c);
	}
	int ans=0;

	for(int i=0; i<1000; i++) {
		string s = to_string(i);
		if(s.length() != n) continue;
		bool ok=true;
		rep(j,m) rep(k,n){
			if(k == sv[j] && cv[j] != s[k] - '0') {
				ok = false;
			}
		}
		if (ok) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
h, w, k = [int(i) for i in input().split()]
a = [input() for j in range(h)]

ans = 0
for mi in range(1 << h):
    for mj in range(1 << w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if ((mi >> i) & 1) and ((mj >> j) & 1) and a[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)


Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
	int L, b;
	while( 1 ){
		vector<int> a;
		cin >> b >> L;
		a.push_back(b);
		if( a[0] == 0 && L == 0 ) break;
		int i = 0;
		while( i < 20 ){
			vector<int> rank;
			int max = 0, min = 0;
			int number = a[i];
			//cout << number << ' ';
			for( int j = 0; j < L; j++ ){
				rank.push_back(number % 10);
				number /= 10;
			}
			sort( rank.begin(), rank.end() );
			for( int j = 0; j < L; j++ ){
				max += rank[j] * pow(10.0,(double)j);
			}
			sort( rank.begin(), rank.end(), greater<int>() );
			for( int j = 0; j < L; j++ ){
				min += rank[j] * pow(10.0,(double)j);
			}
			i++;
			a.push_back(max - min);						//a[i] = max -min;
			//cout << max << ' ' << min << ' ' << a[i] << endl;
			for( int j = 0; j < i; j++ ){
				if( a[j] == a[i] ){
					cout << j << ' ' << a[i] << ' ' << i - j << endl;
					goto end;
				}
			}
			rank.clear();
		}
	end:
		a.clear();
	}
}

Measured memory_bytes: 1264
A,B = map(int,input().split())


if A == 1 or B == 1:
    if A == B:
        print("Draw")
        exit()
    elif A == 1 and A < B:
        print("Alice")
        exit()
    elif B == 1 and B < A:
        print("Bob")
        exit()

if A < B :
    print("Bob")
elif A > B:
    print("Alice")
else :
    print("Draw")


Measured memory_bytes: 3060
import sys

N, M, X, Y = list(map(int, sys.stdin.readline().strip().split(" ")))
x_list = list(map(int, sys.stdin.readline().strip().split(" ")))
y_list = list(map(int, sys.stdin.readline().strip().split(" ")))

x_max = max(x_list)
y_min = min(y_list)

for Z in range(X+1, Y+1):
    if x_max < Z and y_min >= Z:
        print("No War")
        sys.exit()
print("War")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define PB push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mod 100000000
// #define int ll

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;cin >> n;
	int a[n];for(int i=0;i<n;i++) cin >> a[i];
	ll ans = 0;
	int b[n],c[n];
	for(int i=0;i<n;i++) cin >> b[i];
	for(int i=0;i<n-1;i++) cin >> c[i];
	for(int i=0;i<n;i++){
		ans += b[a[i]-1];
		if(i>0 && a[i]==a[i-1]+1) ans += c[a[i]-2];
	}
	cout << ans << endl;
	
 	return 0;
}

Measured memory_bytes: 256
#正解者以外のポイントを1減らすことと、全員のポイントを1減らしてから正解者のポイントだけ1増やすのは同じこと
from collections import Counter
n, k, q = map(int, input().split())
point = k - q
participant = [point] * n
answer = [int(input()) for _ in range(q)]
count_a = Counter(answer)


for key, value in count_a.items():
    participant[key-1] += value

for i in participant:
    if i > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 18600
n, q = map(int, input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = (1 if s[i:i + 2] == "AC" else 0) + t[i]
for i in range(q):
    l, r = list(map(int, input().split()))
    print(t[r - 1] - t[l - 1])


Measured memory_bytes: 7748
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<map>
#include<cassert>
#include<utility>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<deque>
#include<fstream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<functional>
#include<stack>
using namespace std;
int a[100005];
int num[100005];
int main()
{
	for(int i=0;i<100002;i++)
	num[i]=0;
	int n;
	cin>>n;
	int max=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		num[a[i]+1]++;
		num[a[i]]++;
		num[a[i]-1]++;
	}
	for(int i=0;i<100002;i++)
	if(num[i]>max)
	max=num[i];
	cout<<max<<endl;
	return 0;
 } 

Measured memory_bytes: 1024
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

/** point of coordinate */
data class Point(val x: Int, val y: Int) {
    fun distanceTo(p: Point) = abs(p.x - this.x) + abs(p.y - this.y)
}

fun solve() {
    val (n, m) = readIntegerList()
    val students = Array(n) {
        val (a, b) = readIntegerList()
        Point(a, b)
    }
    val checkPoints = Array(m) {
        val (c, d) = readIntegerList()
        Point(c, d)
    }

    for (s in students) {
        val minIndex = checkPoints
            .mapIndexed { index, point -> Pair(index, point.distanceTo(s)) }
            .minBy { it.second }!!
            .first
        out.println(minIndex + 1)
    }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36336
#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////
/////////////////////////
//#include<bits/stdc++.h>
using namespace std;
#define Base1   101LL
#define Base2   10000079LL
#define Base3   10000103LL
#define MOD1    1000000007LL
#define MOD2    1000000009LL
#define MOD3    1000000021LL
#define mx 100000//Number of charter of main string
#define mx1 25000// Number off character of total charcater
#define mx2 500// Number of pattern and number of ch of each pattern

int main(){

   int n;
   I(n);
   int mi = n + 1;
   int cnt = 0;
   for(int i = 1;i<=n;i++){
       int x;
       I(x);
       if(mi >= x){
           cnt ++;
           mi = x;
       }
       
   }
   cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        long X=Math.abs(sc.nextLong());
        long K=Math.abs(sc.nextLong());
        long D=Math.abs(sc.nextLong());
        long result=0;
        if(X/D-K>0){
            result=X-K*D;
        }else{
            if(K%2==1){
                X=Math.abs(X-D);
                K=K-1;
            }
            long K2=((long)(X/D/2))*2;
            result=Math.min(X-K2*D,Math.abs(X-(K2+2)*D));
        }


        System.out.println(result);

    }
}

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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    set<char> s;
    char c;
    FOR(i,0,t){
        cin >> c;
        s.insert(c);
    }
    if(s.size() == 4){
        cout << "Four" << endl;
    }
    else{
        cout << "Three" << endl;
    }
}   

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

main(){
     ios_base::sync_with_stdio(false);
     cin.tie(nullptr);
     int N; cin >> N; N = N % 10;
     if(N == 3) cout << "bon";
     else if(N == 0 || N == 1 || N == 6 || N == 8) cout << "pon";
     else cout << "hon";
}

Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int r, c;
    int m[101][101] = {};
    cin >> r >> c;
    for (int i = 0; i < r; i++){
        for (int j = 0; j < c; j++){
            cin >> m[i][j];
            m[i][c] += m[i][j];
            m[r][j] += m[i][j];
            m[r][c] += m[i][j];
        }
    }
    for (int i = 0; i <= r; i++){
        for (int j = 0; j < c; j++){
            cout << m[i][j] << " ";
        }
        cout << m[i][c] << endl;
    }
}


Measured memory_bytes: 3156
a, b = map(int, input().split())

def small(a, b):
    return a < b
    
def big(a, b):
    return a > b
    
def equal(a, b):
    return a == b
    
if a < b:
    print('a < b')
elif a > b:
    print('a > b')
else:
    print('a == b')


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <cstdio>

#define MAX_V 200005

using namespace std;

vector<int> tree[MAX_V];
long long ans[MAX_V];

int cost[MAX_V] = {0};

void dfs(int v, int p) {
  ans[v] += cost[v];
  if (p != -1) { ans[v] += ans[p]; }
  for (int i = 0; i < tree[v].size(); i++) {
    int e = tree[v][i];
      if (e == p) { continue; }
      dfs(e, v);
  }
}
 
int main() {
  int N, Q;
  scanf("%d %d", &N, &Q);

  for (int i = 0; i < N-1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  for (int i = 0; i < Q; i++) {
    int p, x;
    scanf("%d %d", &p, &x);
    cost[p-1] += x;
  }

  dfs(0, -1);

  for (int i = 0; i < N; i++) {
    cout << ans[i] << ( i == N-1 ? "\n" : " ");
  }
  return 0;
}

Measured memory_bytes: 24832
from bisect import bisect_left
 
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        ans += bisect_left(L, L[i] + L[j])  - j - 1
print(ans)

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

int main() {
    int n;
    cin >> n;
    for( int i = 1; i <= n; ++i ) {
        if( i % 3 == 0 ) {
            cout << " " << i;
            continue;
        } else {
            int x = i;
            while( true ) {
                if( x % 10 == 3 ) {
                    cout << " " << i;
                    break;
                } else if( x /= 10 ) {
                    continue;
                } else {
                    break;
                }
                    
                    
            }
        }
    }
    cout << endl;
 
}

Measured memory_bytes: 1164
import java.util.*;
import java.math.*;
public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        for(int i = 0;i <= n;i++){
            if(i%3==0||i%5==0){
                ;
            }else{
                ans+=i;
            }
        }
        System.out.println(ans);
    }    
}







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

int main(){
  cout << fixed << setprecision(10);
  double n,m,d;
  cin >> n >> m >> d;

  double ans;
  if(d==0)  ans=(n-d)*(m-1)/(n*n);
  else  ans=(n-d)*2*(m-1)/(n*n);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let nums: Vec<i64> = buf
        .split_whitespace()
        .filter_map(|x| x.parse::<i64>().ok())
        .collect();
    let x = nums[0];
    let y = nums[1];
    if y % 2 == 1 {
        println!("No");
    } else if 2 * x <= y && y <= 4 * x {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main() {
  int r, g,b;cin>> r>>g>>b;
  int a = 100 * r + 10 * g + b;
  if (a % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3640
import math

def countHugs(input_string):
  string_arr = [char for char in input_string]
  hugs = 0
  for r in range(0, (math.ceil(len(string_arr)/2))):
    pointerA = string_arr[r]
    pointerB = string_arr[-(r+1)]
    if pointerA != pointerB:
      hugs += 1
  print(hugs)

if __name__ == "__main__":
    input_string = input()
    countHugs(input_string)

Measured memory_bytes: 3060
import sys
#from me.io import dup_file_stdin

#@dup_file_stdin
def solve():
    index = dict()
    for line in sys.stdin:
        word,page = line.split(' ')
        pages = index.get(word,list())
        pages.append(int(page))
        index[word] = pages
    keys = list(index.keys())
    keys.sort()
    for key in keys:
        print(key)
        pages = index[key]
        pages.sort()
        print(" ".join(map(str,pages)))
solve()

Measured memory_bytes: 7636
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
using namespace std;
typedef long long llint;
typedef long double ld;
#define inf 1e18

llint n;
llint a;
void solve(){
	cin >> n;
	llint all=1;
	llint bad=1;
	for(int i=0;i<n;i++){
		cin >> a;
		all*=3;
		if(a%2==0){
			bad*=2;
		}
	}
	cout << all-bad << endl;

}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

using namespace std;

int main(){
    long long n;
    priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> Q;
    cin >> n;
    for(int i=0;i<n;i++){
        long long tmpa, tmpb;
        cin >> tmpa >> tmpb;
        Q.push(make_pair(tmpb, tmpa));
    }
    long long _sum=0;
    bool ans=true;
    while(!Q.empty()){
        _sum+=Q.top().second;
        if(_sum > Q.top().first){
            ans=false;
            break;
        }
        Q.pop();
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 6512
n = int(input())
sp = []
for i in range(n):
    spi = list(input().split())
    spi[1] = int(spi[1])
    spi.append(i+1)
    sp.append(spi)

nsp = sorted(sp, key=lambda x: x[1], reverse=True)
nsp = sorted(nsp, key=lambda x: x[0])

for i in range(n):
    print(nsp[i][2])


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

def main():
    while True:
        n, x = map(int, input().split())
        if n == 0 and x == 0:
            break

        ans = 0
        for i in range(1, n+1):
            for j in range(i+1, n+1):
                for k in range(j+1, n+1):
                    if i+j+k == x:
                        ans += 1
        print(ans)


if __name__ == "__main__":
    main()


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

long long V(vector<long long> x){
  long long ans;
  if(x.size()==1){
    ans=x.at(0);
    return ans;
  }
  else{
    auto itr1=x.begin();
    auto itr2=itr1+1;
    *itr2=*itr1+*itr2;
    x.erase(itr1);
    return V(x);
  }
}

  

int main() {
  long long N,M,A;
  cin>>N>>M;
  vector<long long> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  A=V(a);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  if(a.at(M-1)>(A-1)/4/M){
    cout<<"Yes";
  }
else{
  cout<<"No";
}
  
  
  
}


Measured memory_bytes: 256
# ABC 103 D - Islands War
f=lambda:map(int,input().split())
N,M=f()
wars=[]
for i in range(M):
    l,r=f()
    wars.append((r,l))
wars.sort()

res=M
r,l=wars.pop(0)
for nr,nl in wars:
    if nl<r:
        res-=1
    else:
        r=nr
print(res)

Measured memory_bytes: 83372
N = int(input())
mylist = list(map(int, input().split()))
set = 0

if(N<3):
  print(set)
else:
  for num in range(len(mylist)-2):
    for num2 in range(len(mylist)-1):
      if(num < num2 and mylist[num] != mylist[num2]):
        for num3 in range(N):
          if(num2 < num3 and mylist[num3] != mylist[num] and mylist[num3] != mylist[num2]):
            newlist = [mylist[num], mylist[num2], mylist[num3]]
            if(max(newlist) < sum(newlist)-max(newlist)):
               set += 1
            
  print(set)

Measured memory_bytes: 9224
k,N = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
max = 0
for i in range(N-1):
  if (a[i+1]-a[i]) >= max:
    max = a[i+1]-a[i]
if max <  k -(a[N-1]-a[0]):
  max = k -(a[N-1]-a[0])
min = k-max
print(min)

Measured memory_bytes: 26444
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
  double a,b,theta;
  cin >> a >> b >> theta;
  double S = a*b*sin((theta*M_PI)/180) / 2 ;
  double L = a + b + sqrt(a*a + b*b - 2*a*b*cos(theta*M_PI/180));
  double h = b *sin((theta*M_PI)/180);
  printf("%.10f\n",S);
  printf("%.10f\n",L);
  printf("%.10f\n",h);
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i, S.size()) if (S[i] != T[i]) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 3928
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int h, w, k;
    cin >> h >> w >> k;
    char mass[6][6];
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> mass[i][j];
        }
    }
    int cnt = 0;
    int ans = 0;
    for (int l = 0; l <= (1 << h) - 1; l++)
    {
        for (int m = 0; m <= (1 << w) - 1; m++)
        {
            cnt = 0;
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (((l >> i) & 1) == 0 && ((m >> j) & 1) == 0 && (mass[i][j] == '#'))
                    {
                        cnt++;
                    }
                }
            }
            if (cnt == k)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
var lines = [];

var N, A, B, C;
var l;
var min = Infinity;

var readline = require("readline");

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.on('line', function (x) {
  lines.push(x);
});

rl.on('close', function () {
  N = Number(lines[0].split(" ")[0]);
  A = Number(lines[0].split(" ")[1]);
  B = Number(lines[0].split(" ")[2]);
  C = Number(lines[0].split(" ")[3]);

  lines.shift();

  l = lines.map(value => Number(value));

  dfs(0, []);
  console.log(min);
});

function dfs(n, comb) {
  if (n === N) { calc(comb); }

  else {
    for (var i = 0; i < 4; i++) {
      comb[n] = i; dfs(n + 1, comb);
    }
  }

  return (0);
}

function calc(comb) {
  var bamb_A = 0; var bamb_B = 0; var bamb_C = 0;
  var MP_A = 0; var MP_B = 0; var MP_C = 0;

  for (var i = 0; i < comb.length; i++) {

    if (l[i] !== 0) {
      switch (comb[i]) {
        case 1: bamb_A += l[i]; MP_A++; break;// Aを作るために竹を合成する
        case 2: bamb_B += l[i]; MP_B++; break;// Bを作るために竹を合成する
        case 3: bamb_C += l[i]; MP_C++; break;// Cを作るために竹を合成する
      }
    }
  }

  if (bamb_A > 0 && bamb_B > 0 && bamb_C > 0) {
    MP_A = Math.max(1, MP_A); MP_B = Math.max(1, MP_B); MP_C = Math.max(1, MP_C)
    var result = (10 * (MP_A - 1) + Math.abs(bamb_A - A)) + (10 * (MP_B - 1) + Math.abs(bamb_B - B)) + 10 * (MP_C - 1) + (Math.abs(bamb_C - C));
    min = Math.min(result, min);
  }
}

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

int main() {
  string s;
  cin >> s;
  
  int n = 0;
  for(int i = 0;i < 4;i++){
    if(s.at(i) == '+'){
      n++;
    }
    
    else{
      n--;
    }
  }
    cout << n << endl;
}
  
  


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define ub upper_bound
#define lb lower_bound

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    vector<int> mi;
    vector<int> pl;
    for(int i=0;i<N;i++){
        cin >> vec[i];
        if(vec[i]<0){
            mi.pb(vec[i]);
        }
        else if(vec[i]>=0){
            pl.pb(vec[i]);
        }
    }
    sort(pl.begin(),pl.end());
    sort(mi.rbegin(),mi.rend());
    vector<pair<int,int>> Ans;
    int n=0;
    ll ans;
    if(mi.size()>0&&pl.size()>0){
        if(pl.size()>1){
            n=mi[0]-pl[0];
            Ans.pb(make_pair(mi[0],pl[0]));
            for(int i=1;i<pl.size()-1;i++){
                Ans.pb(make_pair(n,pl[i]));
                n=n-pl[i];
            }
            mi.pb(n);
        }
        ans=pl[pl.size()-1];
        if(pl.size()>1){
            for(int i=1;i<mi.size();i++){
                Ans.pb(make_pair(ans,mi[i]));
                ans-=mi[i];
            }
        }
        else{
            for(int i=0;i<mi.size();i++){
                Ans.pb(make_pair(ans,mi[i]));
                ans-=mi[i];
            }
        }
        cout << ans << endl;
        for(int i=0;i<Ans.size();i++){
            cout << Ans[i].first << " " << Ans[i].second << endl;
        }
        return 0;
    }
    else if(pl.size()==0){
        if(mi.size()>2){
            n=mi[0]-mi[1];
            Ans.pb(make_pair(mi[0],mi[1]));
            for(int i=2;i<mi.size();i++){
                Ans.pb(make_pair(n,mi[i]));
                n=n-mi[i];
            }
            cout << n << endl;
            for(int i=0;i<Ans.size();i++){
                cout << Ans[i].first << " " << Ans[i].second << endl;
            }
            return 0;
        }
        else{
            cout << mi[0]-mi[1] << endl;
            cout << mi[0] << " " << mi[1] << endl;
            return 0;
        }
    }
    else if(mi.size()==0){
        if(pl.size()>2){
            n=pl[0]-pl[1];
            Ans.pb(make_pair(pl[0],pl[1]));
            for(int i=2;i<pl.size()-1;i++){
                Ans.pb(make_pair(n,pl[i]));
                n=n-pl[i];
            }
            ans=pl[pl.size()-1]-n;
            Ans.pb(make_pair(pl[pl.size()-1],n));
            cout << ans << endl;
            for(int i=0;i<Ans.size();i++){
                cout << Ans[i].first << " " << Ans[i].second << endl;
            }
            return 0;
        }
        else{
            cout << pl[1]-pl[0] << endl;
            cout << pl[1] << " " << pl[0] << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)

int main(){
  LL a,b,ans=0;
  cin >> a >> b;
  
  REP(i,a,b+1){
    if(i/10000 == i%10 && (i/1000)%10 == (i/10)%10){
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#ifdef LOCAL
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl
#else
#define dmp(x) void(0)
#endif

template <class t, class u>
void chmax(t &a, u b)
{
  if (a < b)
    a = b;
}
template <class t, class u>
void chmin(t &a, u b)
{
  if (b < a)
    a = b;
}

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;

using vi = vc<int>;
int gcd(int a, int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b)
{
  return (a * b) / gcd(a, b);
}
int fact(int n)
{
  if (n == 0)
    return 1;
  return n * fact(n - 1);
}

int main()
{
  int n;
  cin >> n;
  vector<string> s(n);
  vi t(n);
  rep(i,n){
  	cin >>s[i];
    cin >>t[i];
  }
  string x;
  cin>>x;
  reverse(s.begin(),s.end());
  reverse(t.begin(),t.end());
  int ans=0;
  rep(i,n){
    if(s[i]==x)break;
  	ans+=t[i];
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

struct M {
    long long X;
    long long H;

    bool operator<(const M &another) const
    {
        return X < another.X;
    };
};

int main()
{
    int N, D, A;
    cin >> N >> D >> A;
    D *= 2;
    vector<M> monsters;

    for (int i = 0; i < N; i++) {
        M m;
        cin >> m.X >> m.H;
        monsters.push_back(m);
    }
    
    sort(monsters.begin(), monsters.end());
    vector<M> bombQueue;
    
    int leftIndex = 0;
    int bombIndex = 0;
    int bombQueueSize = 0;
    long long currentDmg = 0;
    long long ans = 0;
    while (leftIndex < N) {
        int i = bombIndex;
        for (; i < bombQueueSize; i++) {
            if (bombQueue[i].X + D >= monsters[leftIndex].X) {
                break;
            } else {
                currentDmg -= bombQueue[i].H;
//                cout << "remove at " << bombQueue[i].X << " with power " << bombQueue[i].H << endl;
            }
        }
        bombIndex = i;
        
        if (monsters[leftIndex].H > currentDmg) {
            M bomb;
            bomb.X = monsters[leftIndex].X;
            long long x = (monsters[leftIndex].H - currentDmg + A - 1) / A;
            bomb.H = x * A;
            currentDmg += bomb.H;
            bombQueue.push_back(bomb);
            bombQueueSize++;
            ans += x;
//            cout << "fire at " << bomb.X << " with power " << x * A << endl;
        }
        leftIndex++;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 12012
#include<bits/stdc++.h>
using namespace std;
int h,w;
char a[55][55];
int d[55][55];
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};
int main()
{
	cin>>h>>w;
	int cnt=0;
	memset(a,'#',sizeof a);
	for(int i=1;i<=h;++i)
	for(int j=1;j<=w;++j)
	{
		cin>>a[i][j];
		if(a[i][j]=='#')
			cnt++;
	}
	queue<pair<int,int> > q;
	q.push({1,1});
	memset(d,-1,sizeof d);
	d[1][1]=0;
	while(!q.empty())
	{
		pair<int,int> t = q.front();
		q.pop();
		int tx=t.first;
		int ty=t.second;
		for(int i=0;i<4;++i)
		{
			int nx = tx+dx[i];
			int ny = ty+dy[i];
			if(a[nx][ny]=='#')
				continue;
			if(d[nx][ny]!=-1)
				continue;
			d[nx][ny]=d[tx][ty]+1;
			q.push({nx,ny});
		}
	}
	if(d[h][w]==-1)
		cout<<-1<<endl;
	else
		cout<<w*h-cnt-d[h][w]-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;

int main() {
	int occurs[101];
	
	for (int i = 0; i < 101; i++) {
		occurs[i] = 0;
	}
	
	int input = -1;
	cin >> input;
	while (input >= 0) {
		occurs[input]++;
		
		input = -1;
		cin >> input;
	}
	
	int maxVal = 0;
	for (int i = 0; i < 101; i++) {
		if (occurs[i] > maxVal) maxVal = occurs[i];
	}
	
	for (int i = 0; i < 101; i++) {
		if (occurs[i] == maxVal) cout << i << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),(OUT(YES),1),(OUT(NO),0))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr,greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p998 = 998244353;
const LL p107 = 1000000007;
const LL p = p107;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
//LL A[SIZE],B[SIZE],C[SIZE];
LL point[SIZE];
bool used[SIZE];
LL solve(){
	cin >> N;
	PQ qu;
	REP(i,N){
		LL X,L;
		cin >> X >> L;
		qu.emplace(X-L,i);
		qu.emplace(X+L,-i);
	}
	LL mx=0;
	while(!qu.empty()){
		int next=abs(qu.top().second);
		if(used[next]) MX(mx,point[next]+1);
		else{
			point[next]=mx;
			used[next]=true;
		}
		qu.pop();
	}
	return mx;
	return NONE;
}
 signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	LL T=1;

	REP(i,T){
		DEFAULT;

	}
	
//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;
 
}


Measured memory_bytes: 18416
#include <iostream>
#include <cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define NIL -1
const int MOD = 1e9+7;
const int INF = 1 << 29;
int n,c[501],s[501],f[501];
ll ans[501];
int main(){
    cin>>n;
    int pos=0;
    rep(i,n-1)cin>>c[i]>>s[i]>>f[i];
    rep(j,n){
        pos=s[j];
    for(int i=j;i<n-1;i++){
        if(pos==s[i])pos+=c[i];
        else if(pos<s[i])pos=s[i]+c[i];
        else if(pos%f[i]==0)pos+=c[i];
        else if(pos>s[i]){
            pos+=c[i]+f[i]-pos%f[i];
        }
    }
    cout<<pos<<endl;

    }
    return 0;
}

Measured memory_bytes: 256
//40
#include<iostream>
#include<utility>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main(){
  queue<pair<vector<int>,int> > que;
  static const int g[]={0,1,2,3,4,5,6,7};
  vector<int> ov(g,g+8);
  que.push(make_pair(ov,0));
  map<vector<int>,int> m;
  while(!que.empty()){
    vector<int> cv=que.front().first;
    if(m.find(cv)!=m.end()){
      que.pop();
      continue;
    }
    m[cv]=que.front().second;
    int z=find(cv.begin(),cv.end(),0)-cv.begin();
    for(int i=0;i<4;i++){
      static const int d[]={1,4,-1,-4};
      int nz=z+d[i];
      if(0<=nz&&nz<8&&!(z*nz==12&&z+nz==7)){
	vector<int> nv=cv;
	swap(nv[z],nv[nz]);
	que.push(make_pair(nv,que.front().second+1));
      }
    }
    que.pop();
  }
  for(;;){
    vector<int> v(8);
    for(int i=0;i<8;i++){
      cin>>v[i];
      if(!cin)return 0;
    }
    cout<<m[v]<<endl;
  }
}

Measured memory_bytes: 3884
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()
    if S[-1] == 's':
        print(S + 'es')
    else:
        print(S + 's')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10036
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void load(void);
void output(void);

int X;

int main(){
	load();
	output();
	return 0;
}

void load(void){
	cin >> X;
}

void output(void){
	int res;
	if(X >= 30){
		cout << "Yes";
	}else{
		cout << "No";
	}
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >>D;
  int X = 0,Y = 0;
  if(A > B){
  	X = B;
  }else{
  	X = A;
  }
  
  if(C > D){
    Y = D;
  }else{
  	Y = C;
  }
  
  cout << X+Y << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;

int H, W, K;

string c[10];

string d[10];

void make_d(int i, int j) {

	for (int u = 0; u < H; u++) { d[u] = c[u]; }

	/*for (int u = 0; u < H; u++) {
		cout << d[u] << endl;
	}*/

	//cout << "i= " <<bitset<8>( i) << "  j= " << bitset<8>( j) << endl;

	vector<int>v;

	int tmp = i;

	for(int k=0;k<H;k++){
		if ((i >> k) & 1) { v.push_back(k); }
	}


	/*cout << "v: ";
	for (auto y : v) { cout << " " << y; } cout << endl;
	*/
	vector<int>w;

	tmp = j;
	for (int k = 0; k < W; k++) {
		if ((j >> k) & 1) { w.push_back(k); }
	}


	/*cout << "w: ";
	for (auto y : w) { cout << " " << y; } cout << endl;
	*/
	int U = v.size();
	int Y = w.size();

	for (int u=0; u < U; u++) {
		for (int y = 0; y < W; y++) {
			d[v[u]][y] = 'R';
		}
	}

	for (int y = 0; y < Y; y++) {
		for (int i = 0; i < H; i++) {
			d[i][w[y]] = 'R';
		}
	}


	

}

int cnt(void) {

	/*for (int u = 0; u < H; u++) {
		cout << d[u] << endl;
	}*/

	int num = 0;

	//cout << "H= " << H << " W= " << W << endl;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			//cout << d[i][j] << endl;
			if (d[i][j] == '#') { num++; }
		}
	}

	//cout << "num= " << num << endl;

	if (num == K) { return 1; }
	return 0;
}

int main(void) {

	cin >> H >> W >> K;

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

	int ans = 0;

	for (int i = 0; i < (1 << H); i++) {
		for (int j = 0; j < (1 << W); j++) {

			make_d(i, j);


			ans += cnt();

		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

int main(){
    ll t; cin >> t;
    REP(i,t){
        ll n; cin >> n;
        ll ans = 0;
        vector<vector<ll>> leftl(n);
        vector<vector<ll>> rightl(n);
        ll leftcnt = 0;
        ll rightcnt = 0;
        REP(i,n){
            ll k,l,r; cin >> k >> l >> r;
            if (l==r) ans+=l;
            else if (k==n) ans+=l;
            else if (l>r){
                ans+=r;
                leftl[k-1].pb(l-r);
                leftcnt++;
            }
            else{
                ans+=l;
                rightl[k].pb(r-l);
                rightcnt++;
            }
        }
        priority_queue<ll,vector<ll>,less<ll>> q1;
        priority_queue<ll,vector<ll>,less<ll>> q2;
        FORD(i,n-1,0){
            REP(j,leftl[i].size()) q1.push(leftl[i][j]);
            if (q1.size()) {
                ans+=q1.top();
                q1.pop();
            }
        }
        FOR(i,0,n-1){
            REP(j,rightl[i].size()) q2.push(rightl[i][j]);
            if (q2.size()){
                ans+=q2.top();
                q2.pop();
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 17388
N = int(input())
Ans = []
for h in range(1, 3501):
    for n in range(h, 3501):
        if 4 * h * n > N * (h + n) and N*h*n % (4*h*n - N*(h+n)) == 0:
            w = N*h*n // (4*h*n - N*(h+n))
            Ans = [h, n, w]
            break
    if Ans:
        break
print(" ".join(map(str, Ans)))


Measured memory_bytes: 3060
import java.util.*;
class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int a,b,c;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        a=a+b;
        b=a-b;
        a=a-b;
        a=a+c;
        c=a-c;
        a=a-c;
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
    }}
        

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>

int main() {
   
   int X,Y;
   
   std::cin >> X >> Y;
   
   int c1 = (Y - 2*X >= 0);
   int c2 = ((Y - 2*X)%2 == 0);
   
   int c3 = (4*X - Y >= 0);
   int c4 = ((4*X - Y)%2 == 0);
   
   if (c1 && c2 && c3 && c4) {
      std::cout << "Yes" << std::endl;
   }
   else {
      std::cout << "No" << std::endl;
   }
   
   return 0;
   
}


Measured memory_bytes: 3100
import collections

sentence = ""
while True:
  try:
    line = input().lower()
    sentence += line
  except EOFError:
    break

c = collections.Counter(sentence)

print("a : {}".format(c['a']))
print("b : {}".format(c['b']))
print("c : {}".format(c['c']))
print("d : {}".format(c['d']))
print("e : {}".format(c['e']))
print("f : {}".format(c['f']))
print("g : {}".format(c['g']))
print("h : {}".format(c['h']))
print("i : {}".format(c['i']))
print("j : {}".format(c['j']))
print("k : {}".format(c['k']))
print("l : {}".format(c['l']))
print("m : {}".format(c['m']))
print("n : {}".format(c['n']))
print("o : {}".format(c['o']))
print("p : {}".format(c['p']))
print("q : {}".format(c['q']))
print("r : {}".format(c['r']))
print("s : {}".format(c['s']))
print("t : {}".format(c['t']))
print("u : {}".format(c['u']))
print("v : {}".format(c['v']))
print("w : {}".format(c['w']))
print("x : {}".format(c['x']))
print("y : {}".format(c['y']))
print("z : {}".format(c['z']))


Measured memory_bytes: 5964
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

const int inf = 1e9+5;

int main()
{
    ios;
    int n,k;
	cin>>n>>k;
	
	vector<int> arr(n);
	
	for(int i=0;i<n;i++)
		cin>>arr[i];
		
	vector<int> dp(n+1,inf);

	
	
	dp[0]=0;
//	dp[1] = abs(arr[1]-arr[0]);
	for(int i=1;i<n;i++)
	{
		for(int j = i-1; j>=max(0, i-k);j--)
			dp[i] = min(dp[j] + abs(arr[j]-arr[i]),dp[i]) ;
	}
		
	cout<<dp[n-1];
	
	return 0;
	
}

Measured memory_bytes: 1024
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
ab.sort(key=lambda x:x[1])
x=0
ans=0
for i in range(m):
    a,b=ab[i][0],ab[i][1]
    if a>x:
        x=b-1
        ans+=1
    else:
        continue
print(ans)


Measured memory_bytes: 59996
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		
		String dream = "dream";
		String dreamer = "dreamer";
		String erase = "erase";
		String eraser = "eraser";
		
		str = str.replaceAll(eraser, "");
		str = str.replaceAll(erase, "");
		str = str.replaceAll(dreamer, "");
		str = str.replaceAll(dream, "");
		
		if(str.length() == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 30236
#include<cstdio>
using namespace std;
int main(){
    int n,m,k,flag=0;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i*(m-j)+j*(n-i)==k){
                flag=1;
            }
        }
    }
    if(flag){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
}

Measured memory_bytes: 128