akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#define rep(i,n) for(int i = 0 ; i < n ; i++)

using namespace std;

int puzzle[9][9];

void field(int x,int &to,int &from){
  if(0 <= x && x < 3){
    to = 0;
    from = 3;
  }else if(3 <= x && x < 6){
    to = 3;
    from = 6;
  }else{
    to = 6;
    from = 9;
  }
}

bool check1(int x,int y){
  for(int i = x-1 ; i >= 0 ; i--){
    if(puzzle[x][y] == puzzle[i][y]) return false;
  }
  for(int i = x+1 ; i < 9 ; i++){
    if(puzzle[x][y] == puzzle[i][y]) return false;
  }

  return true;
}

bool check2(int x,int y){
  for(int i = y-1 ; i >= 0 ; i--){
    if(puzzle[x][y] == puzzle[x][i]) return false;
  }
  for(int i = y+1 ; i < 9 ; i++){
    if(puzzle[x][y] == puzzle[x][i]) return false;
  }

  return true;
}

bool check3(int x,int y){
  int sx,tx,sy,ty;

  field(x,sx,tx);
  field(y,sy,ty);

  for(int i = sx ; i < tx ; i++){
    for(int j = sy ; j < ty ; j++){
      
      if(x == i && y == j) continue;
      if(puzzle[x][y] == puzzle[i][j]) return false;
    }
  }

  return true;
}

int main(){
  int T;

  cin >> T;
  rep(t,T){
    if(t) cout << endl;

    rep(i,9){
      rep(j,9){
	cin >> puzzle[i][j];
      }
    }

    char ch[9][9];
    rep(i,9){
      rep(j,9){
	ch[i][j] = ' ';
      }
    }

    rep(i,9){
      rep(j,9){
	if(check1(i,j) && check2(i,j) && check3(i,j)) continue;
	ch[i][j] = '*';
      }
    }

    rep(i,9){
      rep(j,9){
	cout << ch[i][j] << puzzle[i][j];
      }
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int intAns = 0;
		int intAns1 = 0;
		//	System.out.println("??°????????\?????????????????????");
			int intTate = sc.nextInt();
			int intYoko = sc.nextInt();
			intAns = intTate * intYoko;
			intAns1 = 2 * intTate + 2 * intYoko;
			System.out.println(intAns+ " " +intAns1);
	}
}

Measured memory_bytes: 26168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int [][] grid = new int[3][3];
		for(int i = 0;i < 3;i++) {
			for(int j = 0;j < 3;j++) {
				grid[i][j] = sc.nextInt();
			}
		}
		if(grid[1][0]-grid[0][0] != grid[1][1]-grid[0][1]) {
			System.out.println("No");
			return;
		}
		if(grid[1][1]-grid[0][1] != grid[1][2]-grid[0][2]) {
			System.out.println("No");
			return;
		}
		if(grid[2][0]-grid[1][0] != grid[2][1]-grid[1][1]) {
			System.out.println("No");
			return;
		}
		if(grid[2][1]-grid[1][1] != grid[2][2]-grid[1][2]) {
			System.out.println("No");
			return;
		}

		if(grid[0][1]-grid[0][0] != grid[1][1]-grid[1][0]) {
			System.out.println("No");
			return;
		}
		if(grid[1][1]-grid[1][0] != grid[2][1]-grid[2][0]) {
			System.out.println("No");
			return;
		}
		if(grid[0][2]-grid[0][1] != grid[1][2]-grid[1][1]) {
			System.out.println("No");
			return;
		}
		if(grid[1][2]-grid[1][1] != grid[2][2]-grid[2][1]) {
			System.out.println("No");
			return;
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 23636
import java.util.Scanner;
class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n;
		
		while(true){
			n = sc.nextInt();
			if(n == 0){
				break;
			}
			System.out.println(new Change(n).getCoin());
		}
	}
}

class Change{
	int coin;
	
	Change(int n){
		coin = 0;
		countCoin(n);
	}
	
	private void countCoin(int n){
		int change = 1000-n;
		
		if(change >= 500){
			change -=500;
			coin ++;
		}
		
		while(change >= 100){
			change -=100;
			coin ++;
		}
		
		while(change >= 50){
			change -=50;
			coin ++;
		}
		
		while(change >= 10){
			change -=10;
			coin ++;
		}
		
		while(change >= 5){
			change -=5;
			coin ++;
		}
		
		while(change >= 1){
			change -=1;
			coin ++;
		}
	}
	
	public int getCoin(){
		return coin;
	}
}

Measured memory_bytes: 15324
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> p(N);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    if (p[i] != i + 1) cnt++;
  }
  if (cnt <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,T,A;
    cin>>N>>T>>A;
    vint h(N);
    REP(i,N) cin>>h[i];
    
    double diff_min=1e18;
    int idx=-1;
    REP(i,N){
        double diff=abs(T-h[i]*0.006-A);
        if(diff<diff_min){
            diff_min=diff;
            idx=i+1;
        }
    }
    cout<<idx<<endl;

}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
Ans = 0

for i in range(N):
  Ans = Ans + B[i]

for j in range(N-1):
  if A[j] == A[j + 1] - 1:
    gain = A[j]
    Ans = Ans + C[gain - 1]

print(Ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define traceloop(x,a) {for(ll i=0;i<x;i++) cerr<<a[i]<<" "; cerr<<endl;}
ll ab(ll x) {return x>0LL?x:-x;}

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

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

priority_queue<int, vector<int>, greater<int>> pq; // lowest in front;


int main() {
    int N, K, A, cnt[200001];
    memset(cnt, 0, sizeof cnt);
    cin >> N >> K;
    for (int i=0;i<N;i++) {
        cin >> A;
        cnt[A]++;
    }
    for (int i=1;i<=N;i++) {
        if (cnt[i]>0) pq.push(cnt[i]);
    }
    long long sum=0;
    while ((int)pq.size() > K) {
        sum += pq.top();
        pq.pop();
    }
    cout << sum << '\n';
}


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

int main(){

    vector<int>A(3);
    cin >>A[0]>>A[1]>>A[2];
    sort(A.begin(),A.end());
    int ans;
    ans=A[2]*10+A[1]+A[0];
    cout<<ans<<endl;

  }


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	long long int A, B, C;

	scanf("%lld", &A);
	scanf("%lld", &B);
	scanf("%lld", &C);

	long long int min = 0;

	if(A%2 == 0 || B%2 == 0 || C%2 == 0){
		
		printf("%lld\n", min);
		return 0;
	
	}else if(A%2 != 0 && B%2 != 0 && C%2 != 0){
	
		long long int temp = 0;

		if(A > B){
			temp = A;
			A = B;
			B = temp;
		}
		
		if(B > C){
			temp = B;
			B = C;
			C = temp;
		}

	min = A * B;
	
	printf("%lld\n", min);

	}


	return 0;

}

Measured memory_bytes: 128
#include<iostream>

using namespace std;
int main()
{
	int n,num_e = 0,now_e = 0,now_w = 0,ans=2e9;
	string s;
	cin >> n >> s;
	for(int i=0; i<n; i++){
		if(s[i] == 'E')
			num_e++;
	}
	for(int i=0; i<n; i++){
		if(s[i] == 'E'){
			now_e++;
			ans = min(ans,num_e - now_e + now_w);
		}
		else{
			ans = min(ans,num_e - now_e + now_w);
			now_w++;
		}
	}
	if(num_e == 0)
		ans = 0;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 900
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  lli n, k;
  scanf("%lld %lld", &n, &k);

  // 2a = pk
  // a + b = qk
  // b = qk - (pk / 2)
  lli cnt = 0;
  for ( lli a = 1; a <= n; a++ ) {
    if ( 2*a % k == 0 )
      cnt += powl((n + a) / k - a / k, 2); 
      // cnt += powl(((n-a) / k + (a-1) / k + 1), 2);
  }
  printf("%lld\n", cnt);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

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

    set<int> s;
    for(int i=0;i<k;i++){
        int d; cin>>d;
        for(int j=0;j<d;j++){
            int a; cin>>a;
            s.insert(a);
        }
    }
    cout<<n-s.size()<<endl;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 3005;
int dp[maxn][maxn]; PII pre[maxn][maxn]; string s,t;

int dfs(const int i, const int j)
{
    if (i == -1 || j == -1)
        return 0;
    int& ans = dp[i][j];
    if (-1 == ans) {
        ans = 0; pre[i][j] = {-1,-1};
        if (s[i] == t[j]) {
            const int res = dfs(i-1,j-1)+1;
            if (res > ans) {
                ans = res;
                pre[i][j] = {i-1,j-1};
            }
        }
        else {
            const int res1 = dfs(i-1,j);
            if (res1 > ans) {
                ans = res1;
                pre[i][j] = {i-1,j};
            }
            const int res2 = dfs(i,j-1);
            if (res2 > ans) {
                ans = res2;
                pre[i][j] = {i,j-1};
            }
        }
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> s >> t) {
        memset(dp,-1,sizeof(dp));
        dfs(s.size()-1,t.size()-1);
        int i = s.size()-1;
        int j = t.size()-1;
        string ans;
        while (i >= 0 && j >= 0) {
            if (s[i] == t[j])
                ans += s[i];
            const PII& p = pre[i][j];
            i = p.first;
            j = p.second;
        }
        reverse(ALL(ans));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 106368
#include<bits/stdc++.h>
using namespace std;
#define MAXN	5005
int main() {
	ios::sync_with_stdio(false);
	double n, d, x, ans = 0;
	cin >> n >> d >> x;
	while (n) {
		ans += d + (2 * n - 1) * x / 2;
		d = ((2 * n + 2) * d + 5 * x) / (2 * n);
		x *= 1.0 + 2.0 / n;
		n--;
	}
	printf("%.12lf\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int n, m;
    cin >> m >> n;
    vector<int> vec(m, 0), fee(m, 0);
    for (int i = 0; i < n; ++i) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if (vec[p] == 0 && s == "WA") {
            ++fee[p];
        }
        if (s == "AC") {
            vec[p] = 1;
        }
    }
    int a = 0, b = 0;
    for (int i = 0; i < m; ++i) {
        if (vec[i] == 1) {
            ++a;
            b += fee[i];
        }
    }
    cout << a << ' ' << b << '\n';
}

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);

  int a[] = {300000, 200000, 100000};
  int ans = 0;
  int x, y;
  cin >> x >> y;
  x--, y--;
  if (x < 3)
    ans += a[x];
  if (y < 3)
    ans += a[y];
  if (x == y && y == 0)
    ans += 400000;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
  vector<int >nos(n+1,0);
  for(int i=1;i<=n;i++)cin>>nos[i];
  int count=0;
  for(int i=1;i<=n;i++)if(i%2!=0 && nos[i]%2!=0)count++;
  cout<<count;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int T,D,L;
  while(1){
    cin>>T>>D>>L;
    if(T==0)break;
    int ans=0,a,last=-1e9;
    for(int i=0;i<T;i++){
      if( i-last <=D ){
        ans++;
      }
      cin>>a;
      if(a>=L)last=i;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::cmp::Reverse;

#[allow(unused_imports)]
use proconio::{fastout, input, marker::Chars};

#[allow(unused_imports)]
use itertools::Itertools;

#[fastout]
pub fn main() {
    input! {
        n: usize,
        k: usize,
        a: [usize; n],
    }
    const MOD: usize = 1000000007;

    let mut dp = vec![vec![0; k + 1]; n + 1];
    dp[0][0] = 1;
    for i in 1..=n {
        let s: Vec<_> = dp[i - 1]
            .iter()
            .scan(0, |acc, x| {
                *acc += *x % MOD;
                Some(*acc)
            })
            .collect();
        for j in 0..=k {
            dp[i][j] = (s[j] + MOD - if j > a[i - 1] { s[j - a[i - 1] - 1] } else { 0 }) % MOD;
        }
    }
    println!("{}", dp[n][k]);
}


Measured memory_bytes: 81860
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.List
import Data.Maybe

m = 10 ^ 9 + 7 :: Integer

solve :: String -> Int -> Integer
solve !s !n =
  (\(_, _, _, x, _) -> x) $
    foldl'
      ( \(!none, !a, !ab, !abc, !s) _ ->
          case head s of
            'A' -> (none, a + none, ab, abc, tail s)
            'B' -> (none, a, ab + a, abc, tail s)
            'C' -> (none, a, ab, abc + ab, tail s)
            _ -> (none * 3, a * 3 + none, ab * 3 + a, abc * 3 + ab, tail s)
      )
      (1, 0, 0, 0, s)
      [1 .. n]

main = do
  s <- getLine
  print $ (`mod` m) . solve s $ length s

Measured memory_bytes: 10852
N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)
for i in range(N-1):
    c, s, f = map(int,input().split())
    C[i], S[i], F[i] = c, s, f
for i in range(N):
    t = 0
    for j in range(i,N-1):
        if t < S[j]: t = S[j]
        elif t%F[j] == 0: pass
        else: t += F[j]-t%F[j]
        t += C[j]
    print(t)




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

int main(){
  int N,M;
  cin >>N>>M;
  int a[N],b[N],c[M],d[M];
  for (int i=0;i<N;i++){
    cin>>a[i]>>b[i];
  }
  for (int i=0;i<M;i++){
    cin>>c[i]>>d[i];
  }
  int mand=0;
  for (int i=0;i<N;i++){
    int manm=999999999;
    int temp=0;
    for (int j=0;j<M;j++){
      mand=abs(a[i]-c[j])+abs(b[i]-d[j]);
        if (mand<manm){
          temp=j;
          manm=min(manm,mand);
        }
    }
    cout<<temp+1<<endl;
  }
  return 0;
}

   
    
      
        
  
    

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    char str[4];
    
    std::cin >> str;
    
    if(str[0] == str[1] && str[1]==str[2]){
        std::cout << "No" << endl;
    }else{
        std::cout << "Yes" << endl;
    }
    return 0;    
}


Measured memory_bytes: 256
fun main(args: Array<String>) {

    val s = readLine()!!.toCharArray().sorted()
    val t = readLine()!!.toCharArray().sortedDescending()
    val sortedS = s.joinToString(separator = "")
    val sortedT = t.joinToString(separator = "")

    val result = if (sortedS < sortedT) "Yes" else "No"

    print(result)
}

Measured memory_bytes: 35792
//A
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	bool ok = 0;
	for(int i = 1;i <= 1000;i++)if(a <= n*i and n*i <= b)ok = 1;
	if(ok)cout << "OK";
	else cout << "NG"; 
	return 0;
}


Measured memory_bytes: 3640
#組み込み関数頼み
n = int(input())
a = set(map(int, input().split( )))
m = int(input())
b = set(map(int, input().split( )))
sm = a|b
#print(sm)
ans = list(sm)
ans.sort()
#print(*ans)
for i in ans:
    print(i)



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

#define SORT(v) sort(v.begin(),v.end())
#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl; 
#define M 1000000007
#define N_MAX 100010

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vp;

vector<vp> path;
vector<vi> gr;
int padre[100];
int depth[100];

void dfs(int nodo, int p){
	padre[nodo] = p;
	for(int x : gr[nodo]){
		if(x == p)
			continue;
		depth[x] = depth[nodo]+1;
		dfs(x, nodo);
	}
}

int main(){
	int n;
	si(n);
	gr.resize(n);
	for(int i = 1; i < n; i++){
		int a, b;
		sii(a, b);
		a--;
		b--;
		gr[a].push_back(b);
		gr[b].push_back(a);
	}
	depth[0] = 0;
	dfs(0, -1);
	int m;
	si(m);
	for(int i = 0; i < m; i++){
		int a, b;
		sii(a, b);
		a--;
		b--;
		vp tmp;
		while(depth[a] > min(depth[a], depth[b])){
			tmp.push_back({a, padre[a]});
			a = padre[a];
		}
		while(depth[b] > min(depth[a], depth[b])){
			tmp.push_back({b, padre[b]});
			b = padre[b];
		}
		while(a != b){
			tmp.push_back({b, padre[b]});
			b = padre[b];
			tmp.push_back({a, padre[a]});
			a = padre[a];
		}
		path.push_back(tmp);
		//cout << "tam: " << tmp.size() << endl;
	}

	ll ans = 0;
	for(ll mask = 1; mask < (1LL<<m); mask++){
		set<pi> ls;
		int cnt = 0;
		for(int i = 0; i < m; i++)
			if(mask&(1<<i)){
				cnt++;
				for(int p = 0; p < path[i].size(); p++)
					ls.insert(path[i][p]);
			}
		if(cnt%2)
			ans += (1LL<<(n-1-(int)ls.size()));
		else
			ans -= (1LL<<(n-1-(int)ls.size()));
		//cout << ans << endl;
	}
	ans = ((1LL<<(n-1)) - ans);
	printf("%lld\n", ans);
	return 0;
}


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


def count_combination(n: int, r: int, mod: int = 10 ** 9 + 7) -> int:
    '''Count the total number of combinations.
        nCr % mod.
        nHr % mod = (n + r - 1)Cr % mod.

    Args:
        n   : Elements. Int of number (greater than 1).
        r   : The number of r-th combinations. Int of number (greater than 0).
        mod : Modulo. The default is 10 ** 9 + 7.

    Returns:
        The total number of combinations.

    Landau notation: O(n)

    See:
    https://qiita.com/derodero24/items/91b6468e66923a87f39f
    '''

    if r > n:
        return 0

    if r > (n - r):
        return count_combination(n, n - r, mod)

    if r == 0 or r == n:
        return 1

    if r == 1:
        return n

    multiple = 1
    division = 1

    for i in range(r):
        multiple *= n - i
        division *= i + 1
        multiple %= mod
        division %= mod

    return multiple * pow(division, mod - 2, mod) % mod


def main():
    n, k = map(int, input().split())
    mod = 10 ** 9 + 7
    ans = 0

    # See:
    # http://drken1215.hatenablog.com/entry/2019/06/30/183400
    for i in range(1, k + 1):
        blue_count = count_combination(k - 1, i - 1)
        red_count = count_combination(n - k + 2 - 1, i + 1 - 1)
        ans = blue_count * red_count
        ans %= mod
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    cout << (a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]?"YES":"NO") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  int a,b;
  cin >> a >> b;
  if((a+b)%2 == 0){
    cout << (a+b)/2 << endl;
  } else {
    cout << (a+b+1)/2 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return -1;
    return 1;
}
int main(int argc, const char * argv[]) {
    int a,b,c,x,y;
    scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
    int p[a],q[b],r[c];
    for(int i=0;i<a;i++){
        scanf("%d",&p[i]);
    }
    qsort(p,a,sizeof(int),compare);
    for(int i=0;i<b;i++){
        scanf("%d",&q[i]);
    }
    qsort(q,b,sizeof(int),compare);
    for(int i=0;i<c;i++){
        scanf("%d",&r[i]);
    }
    qsort(r,c,sizeof(int),compare);
    int array[x+y];
    for(int i=0;i<x;i++){
        array[i]=p[i];
    }
    for(int i=0;i<y;i++){
        array[x+i]=q[i];
    }
    qsort(array,x+y,sizeof(int),compare);
    int ir=0;
    for(int i=x+y-1;i>=0;i--){
        if(array[i]<r[ir]){
            array[i]=r[ir];
            ir++;
        }else{
            break;
        }
    }
    long long ans=0;
    for(int i=0;i<x+y;i++){
        ans+=array[i];
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 3060
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var N = Number(line[0]);
	var a = line[1].split(" ");
	var obj = {};
	for(var i = 0; i < a.length; i++){
		if(obj[a[i]]){
			obj[a[i]]++;
		} else{
			obj[a[i]] = 1;
		}
	}

	var ans = 0;

	for(var key in obj){
		if(Number(key) <= obj[key]){
			ans += obj[key] - Number(key);
		} else{
			ans += obj[key];
		}
	}

	console.log(ans);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 39700
#include <stdio.h>

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

    char s[n + 1], t[n + 1];
    scanf("%s", s);
    scanf("%s", t);

    for(int i = 0; i < n; i++){
        printf("%c", s[i]);
        printf("%c", t[i]);
    }

    return 0;
}

Measured memory_bytes: 128
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

n,l = map(int, input().split())

strs = []
for i in range(n):
    strs.append(input())

for i in range(1,l+1):
    strs.sort(key=lambda x:x[l-i])

for i in range(n):
    print(strs[i], end="")



Measured memory_bytes: 9032
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

const ll INF = 1e18;
const int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int K;
    cin >> K;

    priority_queue<ll, vector<ll>, greater<>> pq;
    REP(i, 9) pq.push(i+1);

    ll cnt = 0;
    while(true) {
        ll e = pq.top(); pq.pop();
        cnt++;
        if (cnt == K) {
            cout << e << endl;
            break;
        }

        int d = e % 10;
        if (d < 9) pq.push(e * 10 + d + 1);
        pq.push(e * 10 + d);
        if (d > 0 ) pq.push(e * 10 + d - 1);
    }
    
}


Measured memory_bytes: 2420
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
    int N, K, Q; cin >> N >> K >> Q;
    vector<int> A(N), B(N);
    rep(i, N) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(all(B));
    int ans = B[Q - 1] - B[0];
    rep(i, N) {
        int X = A[i];
        vector<int> vec, res;
        rep(j, N) {
            if(A[j] >= X) {
                vec.pb(A[j]);
            } 
            if(A[j] < X || j == N - 1) {
                sort(all(vec));
                int M = vec.size();
                rep(k, M - K + 1) {
                    res.pb(vec[k]);
                }
                vec.resize(0);
            }
        }
        sort(all(res));
        if(Q > res.size()) continue;
        int Y = res[Q - 1];
        int ret = Y - X;
        ans = min(ans, ret);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	int[] p = ReadIntArray();

	int ans = 0;

	for (int i = 1; i < n - 1; i++)
	{
	    if ((   p[i-1] < p[i] && p[i] < p[i+1])
		|| (p[i-1] > p[i] && p[i] > p[i+1]) )
	    {
		ans++;
	    }
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 13268
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String,
    }

    let ans = if s.contains("RRR") {3}
              else if s.contains("RR") {2}
              else if s.contains("R") {1}
              else {0};
    println!("{}", ans);
}


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

int main(){
  int A;
  cin >> A;
  long long sum = 0;
  for (int i = 1;i <= A;i++) {
    if  (i % 3 == 0 || i % 5 == 0) {
      continue;
    }
      sum += i;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3600
#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define fi first
#define se second

#ifdef _DEBUG
ifstream ifs("input");
#define input ifs
#else
#define input cin
#endif
#define DEBUG(x) cout<<#x<<": "<<x<<endl

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const double PI = (1*acos(0.0)); 
const double INF = 1e9;
const double EPS = 1e-9;
const double mod = 1e9 + 7;


int main(){
    int x,p;
    input >> x >> p;
    printf("%.7lf", ceil(x/2.0) * (100.0/p));
    return 0;
}


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

using ll = long long;
const int MOD=1e9+7;

const int MAX_N=22;
int N, A[MAX_N][MAX_N];
int dp[MAX_N][1<<MAX_N]; //men, women matched

int dfs(int m, int f)
{
	if(m == N){ 
		return 1;
	}
	if(dp[m][f]!=-1) return dp[m][f];
	ll ans = 0;
	for(int i=0;i<N;++i){
		if(A[m][i] && (f>>i&1)){
			ans = (ans + dfs(m+1, f^(1<<i)))%MOD;
		}
	}
	return dp[m][f]=ans;
}

void solve()
{
	memset(dp,-1, sizeof(dp));
	int ans = dfs(0, (1<<N)-1);
	cout << ans << endl;
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i)for(int j=0;j<N;++j)cin>>A[i][j];
	solve();
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);

	int N; cin >> N;
	bool over = false, any_zero = false;
	int64_t product = 1;
	for (int i = 0; i < N; ++i) {
		int64_t a; cin >> a;
		if (a == 0) any_zero = true;
		if (over) continue;
		over |= __builtin_smull_overflow(product, a, &product);
		if (!over) over |= product > (int64_t)1e18;
	}

	if (over) {
		cout << (any_zero ? 0 : -1) << endl;
	}
	else {
		cout << product << endl;
	}
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

int c[10][10];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	rrep(i, n + 1) {
		int tmp = i;
		int a = tmp % 10;
		while (tmp >= 10) tmp /= 10;
		c[tmp][a]++;
	}
	int ans = 0;
	rrep(i, 10)rrep(j, 10) ans += c[i][j] * c[j][i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
n = int(input())
a = list(map(int, input().split()))

d = [0 for _ in range(9)]
for x in a:
    p = x // 400
    if p >= 8:
        d[8] += 1
    else:
        d[p] = 1
        
if sum(d) == d[8]:
    print(1, d[8])
else:
    print(sum(d) - d[8], sum(d))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
//main
signed main(){
  int N;cin>>N;
  std::vector<int> edge[N];
  for(int i=1;i<N;i++){
    int u,v;cin>>u>>v;u--;v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  int K;cin>>K;
  std::vector<int> mx(N,LINF),mn(N,-LINF);
  while(K--){
    int r,p;cin>>r>>p;r--;
    mx[r]=mn[r]=p;
  }
  std::vector<int> parent(N,-1),in(N),ans(N);
  queue<int> que;
  for(int i=0;i<N;i++)
    if((in[i]=edge[i].size())==1)que.push(i);
  while(que.size()){
    int p=que.front();que.pop();
    for(int q:edge[p]){
      if(parent[q]==p)continue;
      parent[p]=q;
      mx[q]=min(mx[q],mx[p]+1);
      mn[q]=max(mn[q],mn[p]-1);
      if(--in[q]==1)que.push(q);
    }
  }
  for(int i=0;i<N;i++)if(parent[i]<0)que.push(i);
  while(que.size()){
    int p=que.front();que.pop();
    if(mx[p]<mn[p])fin("No");
    ans[p]=mx[p]=mn[p];
    if(parent[p]>=0)if(ans[p]==ans[parent[p]])fin("No");
    for(int q:edge[p]){
      if(parent[q]!=p)continue;
      mx[q]=min(mx[q],mx[p]+1);
      mn[q]=max(mn[q],mn[p]-1);
      que.push(q);
    }
  }
  cout<<"Yes"<<endl;
  for(int i=0;i<N;i++)cout<<ans[i]<<endl;
}


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

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  int ans = 0;
  vector<string> s(h);

  for (int i = 0; i < h; i++) cin >> s[i];

  for (int is = 0; is < (1<<h); is++) { //横の列を消す場合
    for (int js = 0; js < (1<<w); js++) { // 縦の列を消す場合
      int cnt = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) { //すべてのマスを見る
          if (is >> i & 1) continue; // その列のi番目のビットが1なら(i.e.その列のi番目が消されているなら)
          if (js >> j & 1) continue;
          if (s[i][j] == '#') cnt++;
        }
      }
      if (cnt == k) ans++;
    }
  }

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


Measured memory_bytes: 3632
import math
n, d = map(int, input().split())
points = [list(map(int, input().split())) for i in range(n)]

cnt = 0

def distance(x, y):
  ans = 0
  for dd in range(d):
    ans += abs(x[dd] - y[dd]) ** 2
  return math.sqrt(ans)


for i in range(n):
  for j in range(i+1, n):
    if distance(points[i], points[j]).is_integer():
      cnt += 1

print(cnt)


Measured memory_bytes: 3064
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [[0]*(n+1) for _ in range(n+1)]
# for i in range(1,n+1):
#     dp[i][0] = float("inf")
for i in range(1, n+1):
    hh = h[i-1]
    for j in range(1, n+1):
        if j==1:
            dp[i][j] = hh
        elif j<=i:
            if i>=2:
                dp[i][j] = min((dp[ii][j-1] + max(0, hh-(h[ii-1] if ii>=1 else 0))) for ii in range(1,i))
            else:
                dp[i][j] = hh
        else:
            dp[i][j] = float("inf")
ans = min(min(dp[nn][kk] for kk in range(n-k, n+1)) for nn in range(1,n+1))
print(ans)

Measured memory_bytes: 77868
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <cmath>         // sqrt
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

int main()
{
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  ll x = min(B - 1, N);
  ll tmp = floor(A * x / B) - A * floor(x / B);

  ans = max(ans, tmp);

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


Measured memory_bytes: 3584
using System;
using System.Linq;
public class B{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        int[] v = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] c = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] a = new int[n];
        for (int i=0;i<n;i++){
            a[i] = v[i]-c[i];
        }
        int ans = 0;
        for (int i = 0;i<n;i++){
            if (a[i]>0){
                ans += a[i];
            }
        }
        System.Console.WriteLine(ans);
    }
}


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

int main() {
	int N, T, A, X;
	cin >> N >> T >> A;
	int res = 0;
	int cc = 1 << 30;
	for (int i = 1; i <= N; i++) {
		cin >> X;
		int d = (T * 1000 - X * 6) - A * 1000;
		if (d < 0) d = -d;
		if (cc > d) cc = d, res = i;
	}

	cout << res << endl;

}

Measured memory_bytes: 256
N, Q = map(int, input().split())

A = [[] for _ in range(N)]

for _ in range(Q):
    query = list(map(int, input().split()))
    if query[0] == 0:
        A[query[1]].append(query[2])
    elif query[0] == 1:
        print(*A[query[1]])
    elif query[0] == 2:
        A[query[1]].clear()


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

int main()
{
	int N;
	cin >> N;
	vector<int> dp(N);
	for (int i = 0; i < N; i++) {
		int P;
		cin >> P; --P;
		dp[P] = max(dp[P], (P > 0 ? dp[P - 1] : 0) + 1);
	}
	cout << N - *max_element(dp.begin(), dp.end()) << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){

  int i, n, a;
  long min, max, sum = 0;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a);
    sum += a;
    if(i ==0){
      min = a;
      max = a;
    }
    else{
        if(max < a){
          max = a;
        }
        if(a < min){
          min = a;
        }
    }
  }
  printf("%ld %ld %ld\n", min, max, sum);
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#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)



int main(void){

	int N, M; scanf("%d %d", &N, &M);

	vector<pair<int, int>> store(N);
	REP(i,N){
		int A, B;
		scanf("%d %d", &A, &B);
		store[i] = make_pair(A,B);
	}

	SORT(store);

	long long ans = 0;
	int cnt = 0;
	REP(i,N){
		int buy = min(M, store[i].second);
		ans += (long long)buy * store[i].first;
		M -= buy;
	}


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

	return 0;

}


Measured memory_bytes: 1024
import math
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    _x = []
    _y = []
    for _ in range(n):
        x, y = input_int_list()
		# 座標系を45度回転させて考える
        _x.append(x - y)
        _y.append(x + y)
	
    ans = max(max(_x) - min(_x), max(_y) - min(_y))

    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 93692
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b,c,d,f,g;
  cin>>a>>b>>c;
  d=min(a,min(b,c));
  f=max(a,max(b,c));
  g=a+b+c-d-f;
  cout<<d*g/2;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/arc092/submissions/13926597
# 最大流で解くという発想

# https://tjkendev.github.io/procon-library/python/max_flow/ford-fulkerson.html


# Ford-Fulkerson algorithm
class FordFulkerson:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def dfs(self, v, t, f):
        if v == t:
            return f
        used = self.used
        used[v] = 1
        for e in self.G[v]:
            w, cap, rev = e
            if cap and not used[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        f = INF = 10 ** 9 + 7
        N = self.N
        while f:
            self.used = [0] * N
            f = self.dfs(s, t, INF)
            flow += f
        return flow


def main():
    N = int(input())

    reds = [tuple(map(int, input().split())) for _ in range(N)]
    blues = [tuple(map(int, input().split())) for _ in range(N)]

    ff = FordFulkerson(N * 2 + 2)
    for i, (rx, ry) in enumerate(reds, start=1):
        ff.add_edge(fr=0, to=i, cap=1)
        for j, (bx, by) in enumerate(blues, start=N + 1):
            if rx < bx and ry < by:
                ff.add_edge(fr=i, to=j, cap=1)

    for j in range(N + 1, N * 2 + 1):
        ff.add_edge(fr=j, to=N * 2 + 1, cap=1)

    ans = ff.flow(0, N * 2 + 1)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
import heapq
N,M=map(int, input().split())
A=list(map(int, input().split()))
for i in range(N):
    A[i]=-1*A[i]
heapq.heapify(A)
for i in range(M):
    q=heapq.heappop(A)
    q=q/2
    heapq.heappush(A,q)
for i in range(N):
    A[i]=-1*int(A[i])
print(sum(A))

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

using namespace std;
using ll = long long int;

void inv(vector<int>& v) {
    int length = v.size();
    for (int i = 0; i < length; i++) {
        cin >> v[i];
    }
}
void inv(vector<int>& v, int length) {
    for (int i = 0; i < length; i++) {
        cin >> v[i];
    }
}

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

    int ac = 0, wa = 0, tle = 0, re = 0;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;

        if (s == "AC") {
            ac++;
        } else if (s == "WA") {
            wa++;
        } else if (s == "TLE") {
            tle++;
        } else {
            re++;
        }
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pii pair<int,int>
const int N=200005;
pii f[N],A[N];
int flag[N],l,n,a[N],b[N],c[N],tot,x,y,Ans[N],Q;
struct Tree{
	int l,r,num,flag;
}T[N*4];
int cmp(pii x,pii y){
	return x.se>y.se;
}
void build(int x,int l,int r){
	T[x].l=l;T[x].r=r;
	if (l==r)return;
	int mid=(l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
}
void down(int x){
	T[x*2].num+=T[x].flag;
	T[x*2+1].num+=T[x].flag;
	T[x*2].flag+=T[x].flag;
	T[x*2+1].flag+=T[x].flag;
	T[x].flag=0;
}
void insert(int x,int l,int r,int z){
	if (T[x].l>r||l>T[x].r)return;
	if (T[x].l>=l&&T[x].r<=r){
		T[x].num+=z;
		T[x].flag+=z;
		return;
	}
	down(x);
	insert(x*2,l,r,z);
	insert(x*2+1,l,r,z);
}
int find(int x,int y){
	if (T[x].l==T[x].r)return T[x].num;
	down(x);
	int mid=(T[x].l+T[x].r)/2;
	if (y<=mid)return find(x*2,y);
	return find(x*2+1,y);
}
int ef(int x){
	if (x<=c[0])return 0;
	int l=0,r=n;
	while (l<r){
		int mid=(l+r+1)/2;
		if (c[mid]<x)l=mid;
		else r=mid-1;
	}
	return l+1;
}
void up(int x){
	if (x==1)return;
	if (f[x]<f[x/2]){
		swap(f[x],f[x/2]);
		up(x/2);
	}
}
void down2(int x){
	int i=x;
	if (x*2<=l&&f[x*2]<f[x])i=x*2;
	if (x*2<l&&f[x*2+1]<f[i])i=x*2+1;
	if (i!=x){
		swap(f[x],f[i]);
		down2(i);
	}
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
	for (int i=0;i<=n;i++)scanf("%d",&c[i]);
	sort(c,c+n+1);
	for (int i=1;i<=n;i++)a[i]=ef(a[i]),b[i]=ef(b[i]);
	build(1,0,n);
	for (int i=0;i<=n;i++)insert(1,i,n,-1);
	for (int i=1;i<=n;i++)insert(1,a[i],n,1);
	for (int i=1;i<=n;i++)
		if (b[i]<a[i])A[++tot]=mp(b[i],a[i]-1);
	sort(A+1,A+tot+1,cmp);
	int Flag=1,ans=n;
	for (int i=n,j=1;i>=0;i--){
		while (j<=tot&&A[j].se>=i){
			f[++l]=mp(A[j].fi,j);
			up(l);
			j++;
		}
		while (find(1,i)<-1){
			if (!l){
				Flag=0;
				break;
			}
			insert(1,A[f[1].se].fi,A[f[1].se].se,1);
			flag[f[1].se]=1;
			f[1]=f[l--];down2(1);ans--;
		}
	}
	int num=0;
	for (int i=1;i<=tot;i++)
		if (!flag[i])A[++num]=A[i];
	sort(A+1,A+num+1);
	int Max=-1;
	if (Flag)Ans[0]=ans;
	else Ans[0]=-1e9;
	for (int i=0,j=1;i<=n;i++){
		while (j<=num&&A[j].fi<=i)Max=max(A[j].se,Max),j++;
		if (find(1,i)==-1){
			if (Max<i)Flag=0;
			else {
				ans--;
				insert(1,i,Max,1);
				Max=-1;
			}
		}
		if (Flag)Ans[i+1]=ans;
		else Ans[i+1]=-1e9;
	}
	scanf("%d",&Q);
	while (Q--){
		scanf("%d%d",&x,&y);
		int ans=-1;
		x=ef(x);y=ef(y);
		ans=max(ans,Ans[x]+1);
		ans=max(ans,Ans[y]);
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 13440