akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
 



const int MAX_V = 100;
 
int d[MAX_V][MAX_V];
int V;
  
void warshall_floyd_init(){
    for(int i = 0; i < V; i++){
        for(int j = 0; j < V; j++){
            if(i == j) d[i][i] = 0;
            else d[i][j] = INF;
        }
    }
}
 
void warshall_floyd() {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}



 int main(){
 	cin>>V;
 	warshall_floyd_init();
 	int r, k, t;
 	for(int i = 0; i < V; i++){
 		cin>>r>>k;
 		r--;
 		for(int j = 0; j < k; j++){
 			cin>>t;
 			t--;
 			d[r][t] = 1;
 		}
 	}
 	warshall_floyd();

 	int p;
 	cin>>p;
 	for(int i = 0; i < p; i++){
 		cin>>r>>k>>t;
 		r--; k--;
 		if(d[r][k] < t){
 			cout<<d[r][k] + 1<<endl;
 		}
 		else cout<<"NA"<<endl;
 	}
 }

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    bool flag = false;
    for (int i=1; i<=1000; i++) {
        int x = i * 0.08; int y = i * 0.1;
        if (x == a and y == b) {
            cout << i << '\n';
            flag = true;
            break;
        }
    }
    if (!flag) cout << -1 <<'\n';
    
    return 0;
}

Measured memory_bytes: 3612
import statistics

n = int(input())
l = input().split()
lst = list(map(int,l))
x = []

for i in range(n):
    x.append(0)
    x[i] = lst[i] - (i+1)

#print(x)
#x.sort()
#print(x)

#b = x[n//2]

b = statistics.median(x)
b = int(b)
#print(b)

sad = 0

#print(lst)

for i in range(n):
    sad += abs(lst[i]-b-i-1)

print(sad)

Measured memory_bytes: 39444
#include <iostream>
#include <vector>
#include <algorithm>

#define LL long long int
using namespace std;

int main(void)
{
	int x, y, z;
	int temp;
	int ans = 0;
	cin >> x >> y >> z;
	temp = z + y;
	x = x - z;

	ans = x / temp;

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

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static int span; // 何日間のスケジューリングをするか
	public static int minus[]; // 26種類のコンテストの飽きやすさ
	public static int plus[][]; // 26種類のコンテストの満足感

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		span = Integer.parseInt(sc.next()); // 何日間のスケジューリングをするか
		minus = new int[26]; // 26種類のコンテストの飽きやすさ
		for (int i = 0; i < 26; i++) {
			minus[i] = Integer.parseInt(sc.next());
		}
		plus = new int[span][26]; // 26種類のコンテストの満足感
		for (int d = 0; d < span; d++) {
			for (int i = 0; i < 26; i++) {
				plus[d][i] = Integer.parseInt(sc.next());
			}
		}

		// 提出用配列を初期化しておく（初期値はまぁ適当に26種類のコンテストをローテーション開催で）
		int teishutu[] = new int[span];
		for (int d = 0; d < span; d++) {
			teishutu[d] = (d % 26) + 1;
		}

		// 貪欲法をやってみよう（ちゃんと貪欲法になっているかは知らん）
		for (int d = 0; d < span; d++) {

			// d日目は何を開催したら満足度最大かを求めて、提出用配列をそれにする
			int bestKaisai = 1;
			int bestScore = -99999;
			for (int i = 0; i < 26; i++) {

				teishutu[d] = i + 1;
				int score = calc(teishutu);
				// System.out.println("★" + i + "\t" + score);

				if (score > bestScore) {
					bestKaisai = i + 1;
					bestScore = score;
				}
			}
			teishutu[d] = bestKaisai;

		}

		// 提出
		for (int d = 0; d < span; d++) {
			System.out.println(teishutu[d]);
		}

	}

	public static int calc(int[] input) {

		int last[] = new int[26]; // 各コンテストが最終開催日から何日経過しているか
		int result = 0; // ユーザ満足度

		for (int d = 0; d < input.length; d++) {

			// lastの更新
			for (int i = 0; i < 26; i++) {
				if (i == input[d] - 1) {
					last[i] = 0;
				} else {
					last[i]++;
				}
			}

			// 開催による満足度アップ
			result += plus[d][input[d] - 1];

			// 日数経過による満足度ダウン
			for (int i = 0; i < 26; i++) {
				result -= minus[i] * last[i];
			}
		}

		return result;
	}
}


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

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

typedef long long ll;

map<ll,int> mp;

int main(){
  ll H, W, N;
  cin >> H >> W >> N;
  vector<ll> a(N), b(N);
  REP(i,N){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  REP(i,N) {
    REP(dy,3)REP(dx,3) {
      ll y = a[i] - dy;
      ll x = b[i] - dx;
      if(y < 0 || y >= H - 2 || x < 0 || x >= W - 2) continue;
      mp[y * W + x]++;
    }
  }

  vector<ll> ret(10, 0LL);
  for(auto e: mp) {
    ret[e.second]++;
  }
  ll sum = 0LL;
  REP(i,9) sum += ret[i + 1];
  ret[0] = (H - 2) * (W - 2) - sum;
  REP(i,10) cout << ret[i] << endl;

  return 0;
}



Measured memory_bytes: 58112
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
using namespace std;

int dp[100000];

int jumps(int h[],int curr)
{
    if(curr==1)
        return 0;
    if(curr==2)
        return abs(h[2]-h[1]);
    if(dp[curr]!=-1)
        return dp[curr];
    else return dp[curr]=min(abs(h[curr]-h[curr-1])+jumps(h,curr-1),abs(h[curr]-h[curr-2])+jumps(h,curr-2));

}

int main()
{
    int i,n;
    cin>>n;
    int h[n+1];
    f(i,1,1+n)
    {
        cin>>h[i];
        dp[i]=-1;
    }
    cout<<jumps(h,n);
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int n,y;
    cin>>n>>y;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i+j>n) continue;
            else if(i*10000+j*5000+(n-i-j)*1000==y){
                cout<<i<<" "<<j<<" "<<(n-i-j)<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int Query(int a) {
	printf("%d\n", a - 1);
	fflush(stdout);
	char p[10];
	scanf("%s", p);
	if (p[0] == 'M')return 1;
	if (p[0] == 'F')return 2;
	return 0;
}
int main() {
	int n;
	scanf("%d", &n);
	int c1 = Query(1);
	if (!c1)return 0;
	int c2 = Query(n);
	if (!c2)return 0;
	int b = 1, e = n;
	while (1) {
		int mid = (b + e) >> 1;
		int ck = Query(mid);
		if (!ck)return 0;
		if ((ck + mid) % 2 != (b + c1) % 2) {
			e = mid;
			c2 = ck;
		}
		else {
			b = mid;
			c1 = ck;
		}
	}

}

Measured memory_bytes: 760
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main(){
    string s, t;
    cin >> s >> t;
    int n = (int)s.size();
    int m = (int)t.size();

    int start = -1;
    if (n >= m) {
        rep(i, n) {
            if (i + m <= n) {
                string u = s.substr(i, m);
                bool ok = true;
                rep(j, m) {
                    if (u[j] == t[j] || u[j] == '?') continue;
                    else {
                        ok = false;
                        break;
                    }
                }
                if (ok) start = max(start, i);
            }
        }
    }
    if (start >= 0) {
        rep(i, n) {
            if (i == start) {
                cout << t;
                i += m - 1;
            } else {
                if (s[i] == '?') cout << 'a';
                else cout << s[i];
            }
        }
        cout << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }
}

Measured memory_bytes: 256
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.10 12:09:11
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rep2(i, x) for (int i = 2; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */
const int N = 200;

bool dp[N + 1];
int cnt[N + 1];

int main() {
    int n;
    scanf("%d", &n);
    rep2(i, n) dp[i] = true;

    int sqn = sqrt(n);
    rep2(i, sqn) {
        if (!dp[i])
            continue;
        for (int j = i * i; j <= n; j += i)
            dp[j] = false;
    }

    vector<int> primes;
    rep2(i, n) {
        if (dp[i]) {
            primes.pb(i);
        }
    }

    /* --------------------------------- */

    int pl = primes.size();
    rep2(i, n) {
        int t = i;
        rep(j, pl) {
            int p = primes[j];
            if (t == 1)
                break;
            while (t % p == 0) {
                t /= p;
                cnt[p]++;
            }
        }
    }

    // rep2(i, n) {
    //     printf("%d\n", cnt[i]);
    // }

    int over74 = 0;
    int over24 = 0;
    int over14 = 0;
    int over4 = 0;
    int over2 = 0;

    rep2(i, n) {
        int cn = cnt[i];
        if (cn < 2)
            continue;
        if (cn >= 74)
            over74++;
        if (cn >= 24)
            over24++;
        if (cn >= 14)
            over14++;
        if (cn >= 4)
            over4++;
        if (cn >= 2)
            over2++;
    }

    int ret = 0;

    ret += over74;
    if (over4 > 1) {
        ret += over14 * (over4 - 1);
    }
    if (over2 > 1) {
        ret += over24 * (over2 - 1);
    }
    if (over4 > 1 && over2 > 2) {
        ret += over4 * (over4 - 1) / 2 * (over2 - 2);
    }

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

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(c>=a && c<=b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;





  return 0;
}


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

int main() {
  int N;
  int t[110000], x[110000], y[110000];
  cin >> N;
  t[0] = x[0] = y[0] = 0;
  for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];

  bool can = true;
  for (int i = 0; i < N; ++i) {
      int dt = t[i+1] - t[i];
      int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
      if (dt < dist) can = false;
      if (dist % 2 != dt % 2) can = false;
  }

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

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

#define int long long
const int INF = 1e9+10;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  while ( cin >> n, n ) {
    vector<int> a(n);
    for ( int i = 0; i < n; i++ ) {
      string s;
      cin >> s;
      if ( s == "x" ) a[i] = INF;
      else a[i] = atoi(s.c_str());
    }

    int mi = -INF;
    int ma = INF;
    int cnt = 0;
    bool flag = false;
    for ( int i = 0; i < n; i++ ) {
      if ( a[i] != INF ) {
	if ( i%2 ) {
	  if ( i && a[i-1] != INF ) flag |= (a[i] <= a[i-1]);
	 
	  if ( i < n-1 && a[i+1] != INF ) flag |= (a[i] <= a[i+1]);
	} else {
	  if ( i && a[i-1] != INF ) flag |= (a[i] >= a[i-1]);
	  if ( i < n-1 && a[i+1] != INF ) flag |= (a[i] >= a[i+1]);   
	}
	continue;
      }
      if ( i < n-1 && a[i+1] == INF ) {
	mi = INF+10;
	break;	
      }
      if ( i%2 ) {
	if ( i ) mi = max(mi, a[i-1]+1);
	if ( i < n-1 ) mi = max(mi, a[i+1]+1);	
      } else {
	if ( i ) ma = min(ma, a[i-1]-1);
	if ( i < n-1 ) ma = min(ma, a[i+1]-1);	
      }
    }    

    if ( flag ) cout << "none" << endl; 
    else if ( mi == ma ) cout << mi << endl;
    else if ( mi < ma ) cout << "ambiguous" << endl;
    else cout << "none" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM(f:updMaxMin)
// --> f:updMaxMin
// ---- inserted function updMaxMin from util.cc
template<typename T>
bool updMax(T& tmax, const T& x) {
  if (x > tmax) { tmax = x; return true;  }
  else          {           return false; }
}
template<typename T>
bool updMin(T& tmin, const T& x) {
  if (x < tmin) { tmin = x; return true;  }
  else          {           return false; }
}
// ---- end updMaxMin
// @@ !! LIM  -- end mark --

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  using Pair = pair<ll, ll>;
  vector<Pair> left, right;

  ll diffL = 0;
  ll diffR = 0;
  for (ll z = 0; z < N; z++) {
    string s; cin >> s;
    ll vmin = 0;
    ll acc = 0;
    for (ll i = 0; i < (ll)s.size(); i++) {
      if (s.at(i) == '(') acc++;
      else acc--;
      updMin(vmin, acc);
    }
    if (acc >= 0) {
      left.emplace_back(vmin, acc);
      diffL += acc;
    }else {
      right.emplace_back(vmin - acc, -acc);
      diffR -= acc;
    }
  }

  auto chk = [&](auto& vec) -> bool {
    sort(vec.begin(), vec.end(), greater<Pair>());
    ll cur = 0;
    for (auto& [vmin, acc] : vec) {
      if (cur + vmin < 0) return false;
      cur += acc;
    }
    return true;
  };
  if (diffL == diffR && chk(left) && chk(right)) {
    cout << "Yes\n";
  }else {
    cout << "No\n";
  }
  

  return 0;
}



Measured memory_bytes: 18992
#include <iostream>
#include <cstdlib>

using namespace std;

int main(void)
{
  int N, A1, A2, sum;
  cin >> N;
  int D[N+1];

  cin >> A1;
  D[0] = A1;
  sum = abs(D[0]);

  for(int i=0;i<N-1;i++){
    cin >> A2;
    D[i+1] = A2 - A1;
    sum += abs(D[i+1]);
    A1 = A2;
  }

  D[N] = -A2;
  sum += abs(D[N]);

  for(int i=0;i<N;i++){
    cout << sum + abs(D[i]+D[i+1]) - abs(D[i]) - abs(D[i+1]) << endl;
  }

  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#define endl '\n'
using namespace std;
typedef long long ll;
const ll M = 1000000007;
ll bigm(ll m, ll n)
{
    ll r = 1;
    for(int i=0; i<n; i++)
    {
       r = r*m%M;
    }
    return r;
}
int main(){

    ll n; cin >> n;
    ll ans = bigm(10,n)-bigm(9,n)-bigm(9,n)+bigm(8,n);
    ans%=M;
    ans = (ans+M)%M;
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3608
#include <iostream>
int main(){
        char S[4];
        int Alphabet[26],ans=0;
        std::cin>>S;
        for(int i=0; i<26; i++)
                Alphabet[i]=0;
        for(int i=0; i<4; i++)
                Alphabet[(int)S[i]-'A']++;
        for(int i=0; i<26; i++) {
                if(Alphabet[i]==0||Alphabet[i]==2)
                        continue;
                else
                        ans=1;
        }
        if(ans==0)
                std::cout<<"Yes";
        else
                std::cout<<"No";
        return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

// 6
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long W = sc.nextLong();
		
		long ans = 1;
		
		if(H == 1 || W == 1) ;
		else if(H % 2 == 0)
			ans = (H / 2) * W;
		else {
			if(W % 2 == 0)
				ans = H * (W / 2);
			else
				ans = ((W - 1) / 2) * H + (long)Math.ceil(H / 2.0);
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 35788
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
typedef long long LL;
#define rep(i,n) for(LL i=0; i<(LL)(n); i++)

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

int min(int a,int b) {
	if(a>b) return b;
	else return a;
}

LL ans( LL n,LL xx){
	if(n == -1){
		return 0;
	}
	return (n/xx)+1;
}

//main関数
int main(){
	int H,W,N;
	scanf("%d %d",&H,&W);
	scanf("%d",&N);
	int a[N];
	int bb[N];
	for(int i=1; i<=N; i++){
		scanf("%d",&a[i]);
		if( i != 1){
			bb[i] = a[i] + bb[i-1];
		}
		else {
			bb[i] = a[i];
		}
	}
	
	int ans[H][W];
	int number = 1;
	int sum = 0;
	rep( i , H){
		if( i % 2 == 0){
			for(int j = 0; j<W ; j++){
				ans[i][j] = number;
				sum++;
				if( bb[number] == sum){
					number++;
				}
			}
		}
		else {
			for( int j=W-1; j>=0; j--){
				ans[i][j] = number;
				sum++;
				if( bb[number] == sum){
					number++;
				}
			}	
		}
	}
	rep(i,H){
		rep(j,W){
			printf("%d ",ans[i][j]);
		}
		printf("\n");
	}
}







Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    public class Prog
    {
        const int MOD = 1000000007;
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Prog().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var temp_v = cin.ReadIntArray(n);

            var v = new List<double>();
            for (int i = 0; i < n; i++)
            {
                v.Add((double)temp_v[i]);
            }

            var ans = (double)v[0];
            while (true)
            {
                v = v.OrderBy(x => x).ToList();
                if (v[1] == 1001)
                {
                    break;
                }
                v[0] = (v[0] + v[1]) / 2d;
                v[1] = 1001;
            }

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


Measured memory_bytes: 13524
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    rep(i,N){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        S[i]=s;
    }
    sort(S.begin(),S.end());
    ll res = 0;
    ll tmp = 1;
    rep(i,N-1){
        while(i<N-1&&S[i]==S[i+1]){
            tmp++;
            i++;
        }
        if(tmp>0)res += (tmp*(tmp-1))/2;
        tmp=1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;
import java.awt.RenderingHints.Key;
import java.util.ArrayList;
import java.util.List;

public class Main {
	
	static int inf = 1000000000;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		
		int [][]a = new int [m][2];
		
		
		for(int i = 0 ;i < m ;i++) {
			a[i][0] = Integer.parseInt(sc.next());
			int N = Integer.parseInt(sc.next());
			int num = 0;
			for(int j = 0 ; j < N ;j++) {
				int c = Integer.parseInt(sc.next());
				num += 1<<(c-1);
			}
			a[i][1] = num;
		}
		
		int []dp = new int [1<<n];
		for(int i = 0 ; i < 1<<n ;i++) {
			dp[i] = inf;
		}
		
		dp[0] = 0;
		
		for(int i = 0 ; i < m ;i++) {
			int p = a[i][1];
			for(int j = 0 ; j < 1<<n ;j++) {
				int q = j;
				for(int k = 0 ; k < n ;k++) {
					if(((p>>k)&1) == 1 && ((q>>k)& 1) == 0) {
						 q += 1<<k;
					}
				}
				dp[q] = Math.min(dp[q], dp[j] + a[i][0]);
			}
		}
		if(dp[(1<<n)-1] == inf) {
			System.out.println(-1);
			return;
		}
		System.out.println(dp[(1<<n)-1]);
		
		}
		
	}



Measured memory_bytes: 28272
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <cstdlib>
#include <climits>
#include <set>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc131_a(vector<vector<string>> v) {

    string s = v[0][0];
    
    bool isflg=false;
    
    for(int i=0;i<3;i++){
       
//        cout <<s.substr(i,1) <<" " <<s.substr(i+1,1)<<endl;
        if(s.substr(i,1)==s.substr(i+1,1)){
            isflg=true;
            break;
        }
        
    }
    
    cout << (isflg ? "Bad":"Good") <<endl;
    
    

}

int main() {

        vector<vector <string>> vec_arr_result;
//    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata();

    abc131_a(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll ans;
  string S;
  cin >> S;
  if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]){
    cout << "Bad" << endl;
  }else{
    cout << "Good" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
using namespace std;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define ss(n) scanf("%s",&n)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define mes(a,b) memset(a,b,sizeof a)
#define mem(a,b,n) memset(a,b,n*sizeof(int))
#define uint unsigned int

const  int N = 1e5 + 1000;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

typedef long long ll;
typedef long double ld;

int n;
int arr[N];

int main()
{
	int k, x;
	cin >> k >> x;
	set<int> s;
	fo(i, x, min(1000000, x + k - 1))
		s.insert(i);
	for (int i = x - 1; i > max(-1000000, x - k); i--)
		s.insert(i);
	for (auto i : s)
		cout << i << ' ';

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

using vs=vector<string>;

const char status[]={'.', '#'};

int send_query(vs &query, bool rightward) {
    for (size_t i=0; i<4; ++i) {
        if (rightward) {
            printf("%s%c\n", query[0].c_str(), status[i&1]);
            printf("%s%c\n", query[1].c_str(), status[i>>1]);
        } else {
            printf("%c%s\n", status[i&1], query[0].c_str());
            printf("%c%s\n", status[i>>1], query[1].c_str());
        }
        fflush(stdout);

        char buf[1<<2];
        scanf("%s", buf);
        string ans=buf;

        if (ans == "end") {
            return -1;
        } else if (ans == "T") {
            if (rightward) {
                query[0] += status[i&1];
                query[1] += status[i>>1];
            } else {
                query[0] = status[i&1] + query[0];
                query[1] = status[i>>1] + query[1];
            }
            return 1;
        }
    }
    return 0;
}

int main() {
    size_t N;
    scanf("%zu", &N);

    vs query(2);
    for (int i=0; i<2;) {
        int ans=send_query(query, i);
        if (ans == -1) {
            return 0;
        } else if (ans == 0) {
            ++i;
        }
    }
    return 0;
}


Measured memory_bytes: 716
#include <bits/stdc++.h>
#define ll long long
#define NM (int)2e5
using namespace std;

ll a[NM],b[NM],c[NM],dpa[NM],dpb[NM],dpc[NM];

int main()
{   int n;
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i]>>b[i]>>c[i];

    /// dpa[i] = maximum ai points of happiness from day 1 to i
    /// dpb[i] = maximum bi points of happiness from day 1 to i
    /// dpc[i] = maximum ci points of happiness from day 1 to i
    /// sol = max(dpa[n],dpb[n],dpc[n])

    dpa[1]=a[1];
    dpb[1]=b[1];
    dpc[1]=c[1];
    for(int i=2; i<=n; i++)
    {   dpa[i]=max(dpb[i-1],dpc[i-1])+a[i];
        dpb[i]=max(dpa[i-1],dpc[i-1])+b[i];
        dpc[i]=max(dpa[i-1],dpb[i-1])+c[i];
    }
    cout<<max(max(dpa[n],dpb[n]),dpc[n]);
    return 0;
}

Measured memory_bytes: 8296
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int ans;
int K;

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

    int x = K / 2;

    if (K % 2 == 0) printf("%d\n", x*x);
    else printf("%d\n", x*(x+1));

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int h1,h2,m1,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int diff = (h2 - h1) * 60 + (m2 - m1) - k;
    println(diff);

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string S; cin>>S;
  int n = S.size();
  ll dp[100100][5]; CLR(dp);
  dp[0][0] = 1;
  rep(i,n){
    rep(j,4){
      if(S[i]!='?') dp[i+1][j] += (dp[i][j]%MOD);
      else dp[i+1][j] += (dp[i][j]*3%MOD);
    }
    if(S[i]=='A' || S[i]=='?') dp[i+1][1] += (dp[i][0]%MOD);
    if(S[i]=='B' || S[i]=='?') dp[i+1][2] += (dp[i][1]%MOD);
    if(S[i]=='C' || S[i]=='?') dp[i+1][3] += (dp[i][2]%MOD);
    rep(j,4) dp[i+1][j] %= MOD;
    // cout << S[i] SP dp[i][0] SP dp[i][1] SP dp[i][2] SP dp[i][3]<< endl;
  }
  cout << dp[n][3] << endl;

  return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

P d[9] = {P(1, 2), P(1, 1), P(1, 0), P(1, -1), P(1, -2), P(2, 1), P(2, 0), P(2, -1), P(3, 0)};
int w, h;
bool check[60][30][2];
int cliff[60][30];

struct state {
  P place;
  int cost;
  int left;
};

bool operator<(const state &a, const state &b) {return a.cost > b.cost;}

bool range(int x, int y) {
  return 0 <= x && x < w && 0 <= y && y < h;
}

int main(){
  cin.sync_with_stdio(false);

  while(cin >> w >> h, w) {
    vector<P> s, t;
    rep(i, h)rep(j, w) {
      check[i][j][0] = check[i][j][1] = false;
      char c;
      cin >> c;
      if ('0' < c && c <= '9') cliff[i][j] = c - '0';
      else if (c == 'S') cliff[i][j] = 0, s.pb(P(j, i));
      else if (c == 'T') cliff[i][j] = 0, t.pb(P(j, i));
      else cliff[i][j] = -1;
    }

    priority_queue<state> q;
    rep(i, s.size()) q.push(state{s[i], 0, 0}), q.push(state{s[i], 0, 1});
    int ans = INF;
    bool ok;
    while(!q.empty()) {
      state p = q.top(); q.pop();

      if (check[p.place.se][p.place.fi][p.left]) continue;
      else check[p.place.se][p.place.fi][p.left] = true;

      ok = false;
      rep(i, t.size()) if (p.place == t[i]) ok = true;
      if (ok) {
        ans = p.cost;
        break;
      }

      rep(i, 9) {
        int x = ((p.left == 1) ? p.place.fi - d[i].fi : p.place.fi + d[i].fi), y = p.place.se + d[i].se;
        if (range(x, y) && !check[y][x][(p.left + 1) % 2] && cliff[y][x] >= 0) {
          q.push(state{P(x, y), p.cost + cliff[p.place.se][p.place.fi], (p.left + 1) % 2});
        }
      }
    }

    if (ans == INF) print(-1);
    else print(ans);
  }

  return 0;
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

using P = pair<ll, int>;
using Q = priority_queue<P, V<P>, greater<P>>;

int n;
VV<int> g;
V<ll> lw, us;

V<Q> gx;

V<int> ig;
VV<int> gi;
void uf_init() {
    ig = V<int>(n); gi = VV<int>(n);
    for (int i = 0; i < n; i++) {
        ig[i] = i; gi[i] = {i};
    }
}

bool uf_same(int a, int b) {
    return ig[a] == ig[b];
}

void uf_merge(int a, int b) {
    if (uf_same(a, b)) return;
    int x = ig[a], y = ig[b];
    if (gi[x].size() < gi[y].size()) swap(x, y);
    for (int j: gi[y]) {
        ig[j] = x;
    }
    gi[x].insert(gi[x].end(), gi[y].begin(), gi[y].end());
    gi[y].clear();

    us[x] += us[y];
    us[y] = 0;

    if (gx[x].size() < gx[y].size()) swap(gx[x], gx[y]);
    while (gx[y].size()) {
        gx[x].push(gx[y].top()); gx[y].pop();
    }
}

ll ans;
V<bool> vis;
Q que;

void on(int p) {
    vis[p] = true;
    for (int d: g[p]) {
        if (vis[d]) {
            uf_merge(p, d);
        }
    }
    int x = ig[p];
    while (gx[x].size()) {
        auto tp = gx[x].top();
        if (vis[tp.second]) {
            gx[x].pop();
            continue;
        }
        if (tp.first <= ans+us[x]) {
            on(tp.second);
        } else {
            que.push(P(tp.first - us[x], tp.second));
        }
        break;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
    int m;
    cin >> n >> m;
    g = VV<int>(n);
    lw = V<ll>(n); us = V<ll>(n);
    ll off = 0;
    for (int i = 0; i < n; i++) {
        cin >> lw[i] >> us[i]; lw[i] -= us[i];
        off += us[i];
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b; a--; b--;
        g[a].push_back(b); g[b].push_back(a);
    }
    uf_init();

    gx = V<Q>(n);
    for (int i = 0; i < n; i++) {
        for (int d: g[i]) {
            gx[i].push(P(lw[d], d));
        }
    }
    vis = V<bool>(n);

    for (int i = 0; i < n; i++) {
        que.push(P(lw[i], i));
    }

    ans = 0;
    while (que.size()) {
        P tp = que.top(); que.pop();
        int p = tp.second;
        if (vis[p]) continue;
        ans = max(ans, tp.first);
        on(p);
    }
    cout << ans+off << endl;
    return 0;
}


Measured memory_bytes: 30196
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int a = GetInt();
		int b = GetInt();
		int x = GetInt();

		int mode = (2 * x <= a * a * b) ? 0 : 1;
		solve((double)a, (double)b, (double)x, mode);
	}

	private void solve(double a, double b, double x, int mode)
	{
		double low = 0.0;
		double high = Math.PI / 2.0;
		while(Math.Abs(low - high) > 1e-12)
		{
			double mid = (low + high) / 2.0;
			if(isOK(a, b, x, mid, mode))
				low = mid;
			else
				high = mid;
		}

		double deg = 90.0 - (low / Math.PI) * 180.0;

		Console.WriteLine($"{deg:F9}");

	}

	private bool isOK(double a, double b, double x, double rad, int mode)
	{
		if(mode == 0)
		{
			double S = (b * b * Math.Tan(rad)) / 2.0 ;
			double P = S * a;
			return (P.CompareTo(x) <= 0);
		}
		else
		{			
			double S = a * b - a * a / (2.0 * Math.Tan(rad));
			double P = S * a;
			return (P.CompareTo(x) <= 0);
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n;
    using time = tuple<int, int, int>;
    using train = pair<time, time>;
    while(scanf("%d", &n) && n){
        multiset<train> S;
        rep(i, n){
            int h1, m1, s1, h2, m2, s2;
            scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
            S.insert({make_tuple(h1, m1, s1), make_tuple(h2, m2, s2)});
        }
        int ans = 0;
        while(!S.empty()){
            ++ans;
            int h, m, s;
            tie(h, m, s) = (*S.begin()).se;
            S.erase(S.begin());
            while(true){
                auto it = S.lower_bound({make_tuple(h, m, s), make_tuple(0, 0, 0)});
                if(it == S.end()) break;
                tie(h, m, s) = (*it).se;
                S.erase(it);
            }
        }
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
using ll = long long;
#define itn int
#define int long long
#define all(x) (x).begin(),(x).end()
signed main(void){
    itn n,m,x; cin>>n>>m>>x;
    vector <int> a(m); 
    rep(i,m) cin>>a[i];
    int ans1=0, ans2 = 0;
    rep(i,m){
        if(x<= a[i]) {ans1++; }
    }
    rrep(i,m){
        if(x>=a[i]) ans2++;
    }
   
    cout<<min(ans1, ans2)<<endl;
}


Measured memory_bytes: 256
import heapq
T = int(input())

for _ in range(T):
    N = int(input())
    score = 0
    want_left = []
    want_right = []
    for _ in range(N):
        K, L, R = map(int, input().split())
        if K == N:
            score += L
        elif L == R:
            score += L
        elif L > R:
            want_left.append((K, L-R))
            score += R
        else:
            want_right.append((N-K, R-L))
            score += L

    want_left.sort()
    left_q = []
    index = 0
    i = 0
    while index < len(want_left):
        i += 1
        while index < len(want_left) and want_left[index][0] <= i:
            heapq.heappush(left_q, want_left[index][1])
            index += 1
        while len(left_q) > i:
            heapq.heappop(left_q)
    score += sum(left_q)
    
    want_right.sort()
    right_q = []
    index = 0
    i = 0
    while index < len(want_right):
        i += 1
        while index < len(want_right) and want_right[index][0] <= i:
            heapq.heappush(right_q, want_right[index][1])
            index += 1
        while len(right_q) > i:
            heapq.heappop(right_q)
    score += sum(right_q)

    print(score)

Measured memory_bytes: 97224
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(6) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;

//重み付きUF
struct UnionFind_w {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> diff_weight;
    UnionFind_w(int n){ //最初は全てが根であるとして初期化
        init(n);
    }
    void init(int n) {
        par.resize(n);
        diff_weight.resize(n);
        REP(i,n){
            par[i] = i;
            diff_weight[i] = 0;
        }
    }

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

    int weight(int x){
        root(x);
        return diff_weight[x];
    }

    void unite(int x, int y,int w) { // xとyの木を併合
        w -= weight(x);
        w += weight(y);
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        diff_weight[rx] = w;
    }

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

    int diff(int x,int y){
        return weight(x) - weight(y);
    }
};


signed main(){
    int n,m;
    cin >> n >> m;
    twovec(a,n,m);
    REP(i,n){
        REP(j,m){
            cin >> a[i][j];
        }
    }
    vec(b,m);
    REP(i,m){
        cin >> b[i];
    }
    REP(i,n){
        int ans = 0;
        REP(j,m){
            ans += a[i][j] * b[j];
        }
        print(ans);
    }


    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 3196
# -*- coding: utf-8 -*-
import numpy as np
import sys


def main():
    N, K, Q = map(int, input().split())
    score = np.zeros(N)
    for i in range(Q):
        score[int(input())-1] += 1
    for i in range(N):
        if K - Q +score[i] > 0:
            print("Yes")
        else:
            print("No")








if __name__ =='__main__':
    main()

Measured memory_bytes: 15016
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll h1, w1, h2, w2;

int main(){
	cin >> h1 >> w1 >> h2 >> w2;
	cout << (h1-h2)*(w1-w2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define maxx 1000005
#define mod 998244353LL
using namespace std;
//ll n, m, k, p, x, y, x1, z1, xt, yt;
string s;
bool check = false;
long long a[1000005], ans, t, b[1000005], m, n, kk, T;

vector<ll> arr;
ll k;
void sol()
{
    cin >> s;
    n = s.length();
    s = " " + s;
    a[0] = 0;
    a[n+1] = 0;
    b[0] = 0;
    b[n+1] = 0;
    for(int i = 1; i <= n; i ++)
    {
        if(s[i] == '<')a[i] = a[i-1] + 1;
        else a[i] = 0;
    }
    for(int i = n-1; i >= 0; i --)
    {
        if(s[i+1] == '<')b[i] = 0;
        else b[i] = b[i+1] + 1;
        //cout << b[i] << '\n';
    }
    for(int i = 0; i <= n + 1; i ++)
    {
        ans += max(a[i], b[i]);
        //cout << max(a[i], b[i]) <<" ";
        }
    cout << ans ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("PAPERS.INP", "r", stdin);
    //freopen("PAPERS.OUT", "w", stdout);
    sol();
}


Measured memory_bytes: 11080
#include <iostream>
#include <algorithm>

using namespace std;

static const int N = 1000;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
int main(void){
	int n,a[N];
	cin>>n;
	rep(i,n)cin>>a[i];

	rep(i,n){
		int v = a[i];
		for(int j = i-1 ; j >= 0  && a[j] > v; j --){
			swap(a[j],a[j+1]);
		}
		rep(j,n)cout<<a[j]<<(j==n-1?'\n':' ');
	}

}

Measured memory_bytes: 1164