akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;



int main() {
    int n;
    cin >> n;
    vi a(3*n);
    rep(i, 3*n) {
        cin >> a[i];
    }
    ll sumf=0LL;
    ll sumb=0LL;
    priority_queue<ll, vi, greater<ll> > pqf;
    priority_queue<ll> pqb;
    rep(i, n) {
        sumf += a[i];
        sumb += *(a.end()-i-1);
        pqf.push(a[i]);
        pqb.push(*(a.end()-i-1));
    }

    vi xx(n+1), yy(n+1);
    rep(i, n) {
        xx[i+1] = xx[i];
        yy[i+1] = yy[i];
        
        if(pqf.top() < a[n+i]) {
            xx[i+1] += -pqf.top()+a[n+i];
            pqf.pop();
            pqf.push(a[n+i]);
        }

        if(pqb.top() > a[2*n-1-i]) {
            yy[i+1] += pqb.top()-a[2*n-1-i];
            pqb.pop();
            pqb.push(a[2*n-i-1]);
        }
    }

    ll ma = 0LL;
    rep(i, n+1) {
        ma = max(ma, xx[i]+yy[n-i]);
    }

    cout << sumf-sumb+ma << endl;
}

Measured memory_bytes: 5996
#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> A(N);
  ll prev;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (i > 0) {
      if (A[i - 1] <= A[i]) continue;
      ll cur = A[i - 1] - A[i];
      ans += cur;
      A[i] = A[i] + cur;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n,temp;
	set <int> array;

	cin >>n;
	for(int i=0;i<n;i++){
		cin >>temp;
		array.insert(temp);
	}
	cout<<array.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
List = [list(map(int, input().split())) for i in range(n)]

counter = 0

for i in range(1, 31):
  for j in range(n):
    judge = False
    for k in range(1, len(List[j])):
      if List[j][k] == i:
        judge = True
    if not judge:
      break
  if judge:
  	counter += 1
      

print(counter)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
    int a, b, k;
    scanf("%d%d%d",&k,&a,&b);
    for(int i = a; i <= b; i++)
        if(i % k == 0){
            puts("OK");
            return 0;
        }
    puts("NG");
    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int k;
    string s;
    cin >>s;
    k = s.length();
    for(int  i = 0; i < s.length() -1; i++)
    {
        if (s[i] == s[i+1]) {
            k--;
            i+=2;
        }
    }
    cout <<k;
}

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

typedef long long ll;

int main()
{
	ll n,m;
	cin>>n>>m;
	vector<vector<ll> > g(n+1);
	for(int i=0;i<n-1;i++)
	{
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	// for(int i=1;i<=n;i++)
	// {
	// 	cout<<i<<" -> ";
	// 	for(int j=0;j<g[i].size();j++)
	// 		cout<<g[i][j]<<" ";
	// 	cout<<endl;
	// }
	vector<ll> x(n+1,0);
	for(int i=0;i<m;i++)
	{
		ll u,v;
		cin>>u>>v;
		x[u]+=v;
	}
	// for(int i=1;i<=n;i++)
	// 	cout<<x[i]<<" ";
	// cout<<endl;
	// cout<<"bfs"<<endl;
	vector<ll> ans(n+1,0);
	vector<bool> visited(n+1,false);
	queue<int> q;
	q.push(1);
	ans[1]=x[1];
	visited[1]=true;
	while(!q.empty())
	{
		int u=q.front();
		// cout<<u<<endl;
		for(int i=0;i<g[u].size();i++)
		{
			if(g[u][i]!=u&&!visited[g[u][i]])
			{
				ans[g[u][i]]=x[g[u][i]]+ans[u];
				q.push(g[u][i]);
				visited[g[u][i]]=true;
			}
		}
		q.pop();
	}
	for(int i=1;i<ans.size();i++)
		cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 18672
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

class Coin {
public:
	long long int a;
	long long int b;
	long long int c;
	bool operator <(const Coin& cc)const {
		return c - a < cc.c - cc.a;
	}
	bool operator >(const Coin& cc)const {
		return c - a > cc.c - cc.a;
	}
};

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

	cin >> N >> M >> K;
	vector<Coin>v(N + M + K);
	for (int i = 0; i < N + M + K; i++) {
		cin >> v[i].a >> v[i].b >> v[i].c;
	}
	sort(v.begin(), v.end());
	vector<long long int>ans(N + M + K);
	long long int box = 0;
	priority_queue<long long int>PQ;
	for (int i = 0; i < N; i++) {
		box += v[i].a;
		PQ.push(v[i].b - v[i].a);
	}
	for (int i = N - 1; i < N + M; i++) {
		ans[i] += box;
		PQ.push(v[i + 1].b - v[i + 1].a);
		box += v[i + 1].a;
		box += PQ.top();
		PQ.pop();
	}
	while (!PQ.empty()) {
		PQ.pop();
	}
	box = 0;
	for (int i = N + M; i < N + M + K; i++) {
		box += v[i].c;
		PQ.push(v[i].b - v[i].c);
	}
	for (int i = N + M - 1; i >= N - 1; i--) {
		ans[i] += box;
		PQ.push(v[i].b - v[i].c);
		box += v[i].c;
		box += PQ.top();
		PQ.pop();
	}
	long long int ret = 0;
	for (int i = 0; i < N + M + K; i++) {
		ret = max(ret, ans[i]);
	}
	cout << ret << endl;
	return 0;
}

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

int main(void) {
	int A, B, K;
	scanf("%d %d %d", &A, &B, &K);
	int num = 0;
	for (int i = 100; i > 0; i--) {
		if (A % i == 0 && B % i == 0) {
			num++;
		}
		if (num == K) {
			printf("%d\n", i);
			return 0;
		}

	}
	return 0;
}


Measured memory_bytes: 3816
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List
import           Data.Maybe

type SeqA = [Int]

type ABCD = (Int, Int, Int, Int)

main = do
  [n, m, q] <- readInts <$> BS.getLine
  lines <- replicateM q BS.getLine
  let abcds = map (toABCD . readInts) lines
  print $ solve n m q abcds
  where
    readInts :: BS.ByteString -> [Int]
    readInts = unfoldr (BS.readInt . BS.dropWhile isSpace)
    toABCD :: [Int] -> ABCD
    toABCD [a, b, c, d] = (a, b, c, d)

solve :: Int -> Int -> Int -> [ABCD] -> Int
solve n m q abcds = maximum $ map (score abcds) seqACands
  where
    seqACands :: [SeqA]
    seqACands = dupCombinations 1 m n

score :: [ABCD] -> SeqA -> Int
score abcds seqA = sum $ map (score seqA) abcds
  where
    score :: SeqA -> ABCD -> Int
    score seqA (a, b, c, d)
      | seqA !! (b - 1) - seqA !! (a - 1) == c = d
      | otherwise = 0

dupCombinations :: Int -> Int -> Int -> [SeqA]
dupCombinations low high 0 = [[]]
dupCombinations low high n = do
  aHead <- [low .. high]
  aTail <- dupCombinations aHead high $ n - 1
  return $ aHead : aTail


Measured memory_bytes: 6672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

void mainsolve(){

	string s;
	cin >> s;

	rep(i,s.size()) cout << "x";
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int M=INT_MAX;
void calc(vector<int>A[],vector<int >V,int i,int X,int C,int n)
{

	int flag=0;
	for(int j=1;j<V.size();j++)
	{
		//cout<<V[j]<<" " ;
		if(V[j] < X)
			flag=1;
	}
	//cout<<endl;
	if(!flag)
	{	
		M=min(M,C);
		return ;
	}	
	if(i==n)
		return;
	for(int j=1;j<V.size();j++)
		V[j]+=A[i][j];
	calc(A,V,i+1,X,C+A[i][0],n);
	for(int j=1;j<V.size();j++)
		V[j]-=A[i][j];
	calc(A,V,i+1,X,C,n);
	return ;
}
	
	
int main()
{
	int n,m,x;
	scanf("%d%d%d",&n,&m,&x);
	vector<int> A[n];
	for(int i=0;i<n;i++)
	{
		A[i].resize(m+1);
		for(int j=0;j<=m;j++)
			scanf("%d",&A[i][j]);
	}
	vector<int>V(m+1,0);
	calc(A,V,0,x,0,n);
	if(M==INT_MAX)
		printf("-1\n");
	else
		printf("%d\n",M);
}
	

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main() 
{
  string s; cin >> s;
  for(int  i= 0; i < 2; i++){
    if(s[i] == s[i+1] && s[i+1] == s[i+2]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  system("pause");
}

Measured memory_bytes: 504
A, B, C = map(int, input().split())
a = A
b = B
c = C
count = 0

while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    count += 1
    a_pool = a // 2
    b_pool = b // 2
    c_pool = c // 2
    a = b_pool + c_pool
    b = a_pool + c_pool
    c = a_pool + b_pool
    if a == b == c:
        print(-1)
        exit()

print(count)

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		final int MOD = 1_000_000_007;

		int n = sc.nextInt();

		long ret = 1;
		for (int i = 1; i <= n; i++) {
			ret *= i;
			ret %= MOD;
		}

		pr.println(ret);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23508
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String s = sc.next();
		for (int i=0;i<N;i++) {
			if (i==K-1) {
				System.out.print((char)(s.charAt(i)-'A'+'a'));
			} else {
				System.out.print(s.charAt(i));
			}
		}
	}
}


Measured memory_bytes: 22608
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long X = sc.nextLong();
        long M = sc.nextLong();

        Map<Long,Integer> history = new HashMap<>();

        int newer, older;
        long a = X;
        long[] sum = new long[120000]; // sum[i] : sigma[0,i] a[i]
        for(int i=1;; i++){
            sum[i] = sum[i-1] + a;
            if(history.containsKey(a)){
                newer = i;
                older = history.get(a);
                //System.out.printf("%d : %d, %d\n", a, older, newer);
                break;
            }
            history.put(a, i);
            a = (a*a)%M;
        }

        if(newer >= N){
            System.out.println(sum[(int)N]);
            return;
        }
        long periodCount = (N-newer) / (newer-older);

        long periodSum = sum[newer] - sum[older];

        long restartPoint = newer + (newer-older) * periodCount;
        long s = sum[newer] + periodSum * periodCount;

        //System.err.printf("sum[1, %d] = %d\n", restartPoint, s);

        for(long n=restartPoint+1; n<=N; n++){
            a = (a*a) % M;
            s += a;    
        }

        System.out.println(s);
        
    }
}

Measured memory_bytes: 43200
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    double r;
    cin>>r;
    double PIE=acos(-1);
    printf("%.10lf",PIE*2*r);
    return 0;
}




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

int keta(int N){
  int counter = 1;
  while(N/10 > 0){
    N /= 10;
    counter ++;
  }
  return counter;
}

int beki(int x, int n){
  int res = 1;
  while(n > 0){
    if(n & 1) res *= x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int main(){
  int a, b;
  cin >> a >> b;
  int bketa = keta(b);
  int num = b + a * beki(10, bketa);

  int sq = sqrt(num);
  if(sq * sq == num) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int N;
pair<int, int> A[100000+10];

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N;
    REP(i,N)
    {
        int a;cin>>a;
        A[i] = make_pair(a, i+1);
    }
    sort(A, A+N);
    cout<<A[0].second;
    REP(i,N)
    {
        if (i!=0) cout << " " << A[i].second;
    }
    cout<<endl;
  
    return 0;
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define all(obj) (obj).begin(), (obj).end()
static const int dx[4] = {0, 1, 0, -1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'u', 'r', 'd', 'l'};
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
typedef pair<int, int> pint;

int bfs(const vector<string>& v, int x, int y) {
  int H = v.size(), W = v[0].size();
  vector<vector<int>> dist(H, vector<int>(W, -1));
  queue<pint> que;

  int res = 0;
  que.push({x, y});
  dist[x][y] = 0;
  while (!que.empty()) {
    int x = que.front().first, y = que.front().second;
    res = max(res, dist[x][y]);
    que.pop();
    rep(dir, 4) {
      int nx = x + dx[dir], ny = y + dy[dir];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && v[nx][ny] != '#') {
        if (dist[nx][ny] == -1) {
          dist[nx][ny] = dist[x][y] + 1;
          que.push({nx, ny});
        }
      }
    }
  }
  return res;
}

signed main() {
  int H, W;
  cin >> H >> W;
  vector<string> v(H);
  rep(i, H) { cin >> v[i]; }

  int res = 0;
  rep(x, H) {
    rep(y, W) {
      if (v[x][y] == '#') {
        continue;
      }
      res = max(res, bfs(v, x, y));
    }
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
	int N;
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		int a, b, c;
		scanf("%d %d %d\n", &a, &b, &c);
		puts(((a *a + b*b == c*c) || (a*a + c*c == b*b) || (b*b + c*c == a*a))?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 0
module Main where

import Data.List
import Control.Monad
import Debug.Trace
 
readTuple :: Read a  => IO (a, a)
readTuple = do
    [f, s] <- readLs
    pure (f, s)

readLs :: Read a => IO [a]
readLs = fmap read . words <$> getLine

solve :: String -> Int
solve tiles = foldr (\elem acc -> if elem then acc + 1 else acc) 0 $ shouldConvert <$> zip [0..] tiles where
    firstNumber = head tiles
    shouldConvert (0, value) = False
    shouldConvert (index, value) = if index `mod` 2 == 0 then
        value /= firstNumber 
        else
            value == firstNumber


main = do
    tiles <- getLine
    print $ solve tiles




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

int main() {
	int n; cin >> n;
	vector<vector<int>> xyh(n, vector<int>(3));
	for (int i = 0; i < n; i++) {
		cin >> xyh.at(i).at(0) >> xyh.at(i).at(1) >> xyh.at(i).at(2);
	}
	int x, y;
	for (x = 0; x <= 100; x++) {
		for (y = 0; y <= 100; y++) {
			int l = 0, r = 1000000000 + 300;
			while (l + 1 < r) {
				int c = (l + r) / 2;
				bool flag = true; 
				for (int i = 0; i < n; i++) {
					int X = xyh.at(i).at(0), Y = xyh.at(i).at(1), H = xyh.at(i).at(2);
					if (H > max(c - abs(x - X) - abs(y - Y), 0)) {
						l = c;
						flag = false;
					}
					if (H < max(c - abs(x - X) - abs(y - Y), 0)) {
						r = c;
						flag = false;
					}
					if (!flag) break;
				}
				if (flag) {
					cout << x << " " << y << " " << c << endl;
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,x;
vector<vector<int> >v(12,vector<int>(13));
int mn=INT_MAX;

void slv(int msk=0,int lsti=0,int ttl=0){
    vector<int>v2(m);
    for(int j=0;j<m;j++){
        for(int i=0;i<n;i++){
            if((1<<i)&msk)
                v2[j]+=v[i][j+1];
        }
    }
    int f=1;
    for(int j=0;j<m;j++){
        if(v2[j]<x){
            f=0;
            break;
        }
    }
    if(f){
        mn=min(mn,ttl);
        return;
    }
    for(int i=lsti;i<n;i++){
        if((msk&(1<<i))==0){
            slv(msk|(1<<i),i,ttl+v[i][0]);
        }
    }
}

int main()
{
    cin>>n>>m>>x;
    for(int i=0;i<n;i++){
        cin>>v[i][0];
        for(int j=1;j<m+1;j++)
            cin>>v[i][j];
    }
    slv();
    if(mn==INT_MAX)
    cout<<-1<<'\n';
    else
    cout<<mn<<'\n';
    return 0;

}
/***
3 3 10
60 2 2 4
70 8 7 9
50 2 3 9
3 3 10
100 3 1 4
100 1 5 9
100 2 6 5
*/


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll n;
    cin>>n;
    vector<ll>v(n+1);
    for(ll i=1;i<=n;i++)
        v[i]=0;
    for(ll i=1;i<=n;i++){
        ll mult=i;
        while(mult<=n){
            v[mult]++;
            mult+=i;
        }
    }
    ll sum=0;
    for(ll i=1;i<=n;i++)
        sum=sum+(i*v[i]);
    cout<<sum;
    return 0;
}


Measured memory_bytes: 81380
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD = 1000000007;
const int MAX = 1000010;
long long fac[MAX], finv[MAX], inv[MAX];
void init_comb() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long comb(int n, int r) {
  if (n < r) return 0;
  if (n < 0 || r < 0) return 0;
  return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init_comb();
  int x, y;
  cin >> x >> y;
  ll ans = 0;
  rep(i, x+1) { //i+1を選んだ回数
    if ((x-i)%2 || (x-i)/2+i*2 != y)
      continue;
    (ans += comb(i+(x-i)/2, i)) %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 23680
N=int(input())
List = []
ListMid = []
dictA = {}
res =0
for i in range(N):
  S = input()
  ListMid = list(S)
  ListMid.sort()
  a = tuple(ListMid)
  dictA.setdefault(a,0) 
  dictA[a] += 1
for value in dictA.values():
  if value == 1:
    pass
  else:
    res += value*(value-1)//2
print(res)
  

Measured memory_bytes: 27736
n,m = map(int,input().split())

info = [input().split() for i in range(n)]
achi = []
for i in range(m):
    achi.append(0)

# print(info[0][0])

for i in range(n):
    for j in range(int(info[i][0])):
        num = int(info[i][j+1])
        achi[num-1] += 1


print(achi.count(n))

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始
int n,m;
int g[10][10];

int main(){
  cin>>n>>m;
  for(int i = 0; i < m; i++){
    int a,b;
    cin>>a>>b;
    a--; b--;
    g[a][b] = g[b][a] = 1;
  }
  vector<int> array(n-1);
  for(int i = 1; i < n; i++){
    array[i-1] = i;
  }
  int c=0;
  do{
    int now = 0;
    for(int i = 0; i < array.size(); i++){
      if(g[now][array[i]] == 0) break;
      now = array[i];
      if(i == array.size()-1) c++;
    }
  }while(next_permutation(array.begin(), array.end()));
  cout<<c<<endl;
  return 0;
}


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

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

 if ((A % 1000) % 111 == 0) {
 cout << "Yes" << endl;
 }
 else if ((A - (A % 10)) % 111 == 0){
 cout << "Yes" << endl;  
 }
 else {
 cout << "No" << endl;
 }  
}  

Measured memory_bytes: 256
#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, A, B;
  cin >> N >> A >> B;
  vector<ll> P(N), a, b, c;
  for (int i = 0; i < N; i++) {
    cin >> P[i];
    if (P[i] <= A) {
      a.push_back(P[i]);
    } else if (A < P[i] && P[i] <= B) {
      b.push_back(P[i]);
    } else {
      c.push_back(P[i]);
    }
  }
  cout << min({a.size(), b.size(), c.size()}) << endl;
  return 0;
}

Measured memory_bytes: 3612
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def factorization(N):
    d = {}
    for n in range(2, N + 1):
        tmp = n
        for i in range(2, int(n ** 0.5) + 1):
            if tmp % i == 0:
                cnt = 0
                while tmp % i == 0:
                    cnt += 1
                    tmp //= i
                if i not in d:
                    d[i] = cnt
                else:
                    d[i] += cnt

        if tmp != 1:
            if tmp not in d:
                d[tmp] = 1
            else:
                d[tmp] += 1

    return d


def main():
    N = int(input())
    d = factorization(N)
    d = [v for k, v in d.items() if v > 1]
    cnt = {2: 0, 4: 0, 14: 0, 24: 0, 74: 0}
    cnt[2] = len(d)
    for i in range(len(d)):
        val = d[i]
        if val >= 74:
            cnt[74] += 1
        if val >= 24:
            cnt[24] += 1
        if val >= 14:
            cnt[14] += 1
        if val >= 4:
            cnt[4] += 1

    ans = cnt[74]
    ans += cnt[24] * (cnt[2] - 1)
    ans += cnt[14] * (cnt[4] - 1)
    ans += cnt[4] * (cnt[4] - 1) // 2 * (cnt[2] - 2)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
# coding: utf-8
# Your code here!
N = int(input())

A = [int(input()) for i in range(N)]

max1 = 0
max2 = 0

for j in range(N):
    
    if A[j] > max2:
        if A[j] > max1:
            max2 = max1
            max1 = A[j]
        else:
            max2 = A[j]
            
for j in range(N):
    if A[j] != max1:
        print(max1)
    else:
        print(max2)



Measured memory_bytes: 12532
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
/*typedef struct p{
	string name;
	int num;
}p;*/ 
int main()
{
	int n;
	cin>>n;
	if(n<=1000)
	{
		cout<<1000-n<<endl;

	}
	else
	{
		for(int i=1000;i<=10000;)
		{
			if(n<=i)
			{
				cout<<i-n<<endl;
				break;
			}
		
			else
			i=i+1000;
		}
	}
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
  int x,y;   ;
  while(cin >>x>>y && !(x==0 && y==0)){
    if(x>y)cout<<y<<" "<<x<<endl;
    else if(x<y)cout<<x<<" "<<y<<endl;
    else cout<<x<<" "<<y<<endl;}
    return 0;
  }

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)

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

  int K;
  cin>>K;
  vector<int>A(K);
  for(int i=0;i<K;i++)cin>>A[i];
  ll r=pow(10,15);
  ll l=-1;
  ll m;
  while(r-l>1){
    m=(r+l)/2;
    vector<ll>dp(K+1);
    dp[0]=m;
    for(int i=1;i<=K;i++)dp[i]=(dp[i-1]/A[i-1])*A[i-1];
    if(dp[K]<2)l=m;
    else r=m;
  }
  ll down=r;
  r=pow(10,15);
  l=-1;
  m;
  while(r-l>1){
    m=(r+l)/2;
    vector<ll>dp(K+1);
    dp[0]=m;
    for(int i=1;i<=K;i++)dp[i]=(dp[i-1]/A[i-1])*A[i-1];
    if(dp[K]<=2)l=m;
    else r=m;
  }
  ll up=l;

  bool ok=true;
  vector<ll>dp(K+1);
  dp[0]=down;
  for(int i=1;i<=K;i++)dp[i]=(dp[i-1]/A[i-1])*A[i-1];
  if(dp[K]!=2)ok=false;
  dp[0]=up;
  for(int i=1;i<=K;i++)dp[i]=(dp[i-1]/A[i-1])*A[i-1];
  if(dp[K]!=2)ok=false;

  if(ok)cout<<down<<" "<<up<<endl;
  else cout<<-1<<endl;
  return 0;
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=1e9+7;
const int MAX=1010;



signed main(){
    ll n,x,t;cin>>n>>x>>t;
    ll ans=((n-1)/x+1)*t;
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#define SIZE 2005

using namespace std;
typedef pair <int,int> P;

vector <int> vec[SIZE];
int par[SIZE][SIZE];
int id[SIZE][SIZE];
int ans;

void dfs(int v,int p,int rt)
{
	par[rt][v]=p;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p) dfs(to,v,rt);
	}
}
void add(int a,int b)
{
	if(id[a][b]==b||id[b][a]==a) return;
	if(id[a][b]!=-1) add(id[a][b],b);
	else if(id[b][a]!=-1) add(id[b][a],a);
	else
	{
		//printf("* %d %d\n",a,b);
		id[a][b]=b;
		id[b][a]=a;
		vector <P> nxt;
		queue <int> que;
		que.push(b);
		while(!que.empty())
		{
			int v=que.front();que.pop();
			for(int i=0;i<vec[v].size();i++)
			{
				int to=vec[v][i];
				if(to!=par[a][v])
				{
					if(id[a][to]!=-1) nxt.push_back(P(to,b));
					else
					{
						id[a][to]=b;
						que.push(to);
					}
				}
			}
		}
		que.push(a);
		while(!que.empty())
		{
			int v=que.front();que.pop();
			for(int i=0;i<vec[v].size();i++)
			{
				int to=vec[v][i];
				if(to!=par[b][v])
				{
					if(id[b][to]!=-1) nxt.push_back(P(to,a));
					else
					{
						id[b][to]=a;
						que.push(to);
					}
				}
			}
		}
		for(int i=0;i<nxt.size();i++) add(nxt[i].first,nxt[i].second);
	}
}
void dfs2(int v,int p,int b)
{
	if(id[b][v]==v)
	{
		ans++;
		b=v;
	}
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p) dfs2(to,v,b);
	}
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	for(int i=0;i<n;i++) dfs(i,-1,i);
	memset(id,-1,sizeof(id));
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		add(a,b);
	}
	ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<vec[i].size();j++)
		{
			int to=vec[i][j];
			dfs2(to,i,i);
		}
	}
	printf("%d\n",ans/2);
	return 0;
}


Measured memory_bytes: 32384
#include <iostream>
#define MAX 500000
#define SENTINEL 2000000000
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;

int L[MAX/2+2],R[MAX/2+2];
int cnt;

//統治作業
void merge(int A[], int n,int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    rep(i,n1) L[i]=A[left+i];//左側に分けられた数値を配列L[0],L[1]...と入れていく
    rep(i,n2) R[i]=A[mid+i];//右側に分けられた数値を配列R[0],L[1]...と入れていく
    L[n1]=R[n2]=SENTINEL;//n1,n2はmidに当たる部分なので、同じ値になるはず！
    int i=0,j=0;
    
    for (int k=left; k<right; k++){//右側ブロックvs左側ブロック
        cnt++;
        if(L[i]<=R[j]){
            A[k]=L[i++];
        }else{
            A[k]=R[j++];
        }
    }
}

//分割作業
void mergeSort(int A[], int n, int left, int right){
    if(left+1<right){//部分配列の要素数が１になるまで分割する！
        int mid=(left+right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int main(){
    int A[MAX],n,i;
    cnt=0;
    
    cin >> n;
    rep(i,n) cin >> A[i];
    mergeSort(A,n,0,n);
    rep(i,n){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 6980
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0: break
    for i in range(0, a + 1):
        pt = int(b - 2)
        if i == 0:
            print("#"*b)
        if 0 < i < a - 1:
            print("#" + "."*pt + "#")
        if i == a:
            print("#"*b)
    print()


Measured memory_bytes: 5612
n = int(input())
A = list(map(int, input().split()))

j = 0
while True:
  for i in range(len(A)):
    if A[i] %2 != 0:
      print(j)
      exit()
    else:
      A[i] = A[i]//2
  j += 1
  
print(i)

Measured memory_bytes: 2940
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

ll A,B,h[110000];
int N;

bool check(ll x){
  ll count=0;
  for(int i=0;i<N;i++){
    if(h[i]-B*x<0) continue;
    count+=(h[i]-B*x+A-1)/A;
    if(count>x){
      return false;
    }
  }
  return true;
}

int main(){
  cin>>N>>A>>B;
  A-=B;
  for(int i=0;i<N;i++){
    cin>>h[i];
  }


  ll ng=0,ok=10000000000;
  while(ok-ng!=1){
    ll mid=(ng+ok)/2;
    if(check(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
}


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

template <typename T>
class list{
  private:
    class node{
      public:
      node(node* prev, node* next){
        this->prev = prev;
        this->next = next;
      }
      node(node* prev,T data, node* next){
        this->prev = prev;
        this->data = data;
        this->next = next;
      }
      node* prev;
      T data;
      node* next;
    };
    node* head;
    node* last;
    node* findFirst(void){
      return head->next;
    }
    node* findLast(void){
      return last;
    }
    node* findItem(T item){
      node* cur;
      for (node* cur=head->next;cur!=NULL;cur = cur->next)
        if (cur->data == item)
          return cur;
      return NULL;
    }
    void destroy(node* pNode){
      if (pNode == NULL)
        return;
      if (pNode == last){
        node* last_prev = this->findLast()->prev;
        if (pNode->prev != NULL)
          pNode->prev->next = pNode->next;
        if (pNode->next != NULL)
          pNode->next->prev = pNode->prev;
        else
          delete pNode;
        last = last_prev;
        return;
      }
      if (pNode->prev != NULL)
        pNode->prev->next = pNode->next;
      if (pNode->next != NULL)
        pNode->next->prev = pNode->prev;
      else
      delete pNode;
    }
  public:
    list(){
      head = new node(NULL, NULL);
    }
    void insert(T x){
      node* newNode = new node(head, x, head->next);
      if (head->next==NULL)
        last = newNode;
      head->next    = newNode;
      if (newNode->next != NULL)
        newNode->next->prev = newNode;
    }
    void deleteNode(T x){
      this->destroy(this->findItem(x));
    }
    void deleteFirst(void){
      this->destroy(this->findFirst());
    }
    void deleteLast(void){
      node* last_prev = this->findLast()->prev;
      this->destroy(this->findLast());
      last = last_prev;
    }
    void printItems(void){
      for (node* cur=head->next;cur!=NULL;cur = cur->next){
        if (cur!=head->next) cout << (" ");
        cout << cur->data;
      }
      cout << endl;
    }
};

int main(){
  list<int> linked_list;
  int n;
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i=0;i<n;++i){
    string query;
    int    operand;
    cin >> query;
    if(query == "insert"){
        cin >> operand;
        linked_list.insert(operand);
    }
    else if(query == "delete"){
        cin >> operand;
        linked_list.deleteNode(operand);
    }
    else if(query == "deleteFirst"){
        linked_list.deleteFirst();
    }
    else if(query == "deleteLast"){
        linked_list.deleteLast();
    }
  }
  linked_list.printItems();
}



Measured memory_bytes: 34480
n, $a, $b = gets.chomp.split(" ").map(&:to_i)

$h = []
n.times do
  $h << gets.chomp.to_f
end

def enough(i)
  ret = $h.map{|x| ([(x - i * $b), 0].max / ($a - $b)).ceil}.inject(:+)
  return ret <= i
end

puts (1..$h.max.to_i).bsearch{|i| enough(i)}


Measured memory_bytes: 18044
n = int(input())
A = [int(i) for i in input().split()]

class UnionFind():
  def __init__(self, elements):
    self.elements = elements
    self._root = {}
    self.size = [1] * (len(self.elements)+1)
    for e in self.elements:
      self._root[e] = e
    
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    res = self.size[x] + 1
    self.size[x] += self.size[y]
    
    if x != y:
      self._root[y] = x
      
    return res
    
  def root(self, x):
    if self._root[x] != x:
      self._root[x] = self.root(self._root[x])
    return self._root[x]

B = [0] * (n+1)

for i, a in zip(range(1, n+1), A):
    B[a] = i

uf = UnionFind(range(1, n+1))
ans = 0
A.insert(0, 0)

for j in range(n, 0, -1):
    i = B[j]
    left = 1
    right = 1

    if i - 1 >= 1 and A[i-1] > A[i]:
        left = uf.unite(i-1, i)

    if i + 1 <= n and A[i+1] > A[i]:
        right = uf.unite(i+1, i)
    
    ans += right * left * A[i]

print(ans)

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

const int D = 10;

int d, g, p[D], c[D];

int main() {
  cin >> d >> g;
  rep(i, d) cin >> p[i] >> c[i];
  int ans = 1e4;
  rep(bit, 1<<d) {
    int slv = 0, pt = 0;
    rep(i, d) if (bit & 1<<i) {
      slv += p[i];
      pt += 100 * (1 + i) * p[i] + c[i];
    }
    if (pt >= g) {
      ans = min(ans, slv);
      continue;
    }
    int a = d - 1;
    while (bit & 1<<a) a--;
    if (pt + 100 * (1 + a) * (p[a] - 1) < g) continue;
    slv += (g - pt + 100 * (1 + a) - 1) / (100 * (1 + a));
    ans = min(ans, slv);
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;


int main(){
    ll N, x;
    cin >> N >> x;
    vector<ll> a(N), b(N);
    for(ll i=0; i<N; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    
    for(ll i=0; i<N; i++){
        if(a[i]>x){
            a[i] = x;
        }
    }
    
    for(ll i=0; i<N-1; i++){
        if(a[i]+a[i+1] > x){
            a[i+1] -= a[i]+a[i+1]-x;
        }
    }
    
    ll cnt=0;
    for(ll i=0; i<N; i++){
        cnt += b[i]-a[i];
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int k, n, a0, a_itv_max = 0, abef, aaft;
    cin >> k >> n >> a0;
    abef = a0;
    for(int i = 1; i < n; i++){
        scanf("%d", &aaft);
        a_itv_max = max(a_itv_max, aaft - abef);
        abef = aaft;
    }
    a_itv_max = max(a_itv_max, a0 + k - abef);
    cout << k - a_itv_max << endl;
}

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

using namespace std;

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

    vector<long> A;
    A.reserve(N);
    long i = 0;
    for (int n = 0; n < N; n++) {
        cin >> i;
        A.push_back(i);
    }

    sort(A.begin(), A.end());

    vector<long> L;
    int n = N - 1;
    int cnt = 0;
    while (n > 0) {
        if (A[n] == A[n-1]) {
            L.push_back(A[n]);
            cnt++;
            n = n - 2;
            if (cnt == 2) { break; }
        }
        else { n--; }
    }

    if (cnt != 2) { cout << 0 << endl; }
    else { cout << L[0] * L[1] << endl; }

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a[5];
	for(int i=0;i<5;i++) cin >> a[i];
	sort(a, a+5);
	cout << a[4];
	for(int i = 3; i>=0; i-- ) cout << " " << a[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>  
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define cout(val) cout << (val) << endl
using namespace std;
typedef long long ll;

int main(){
    int n, s = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    rep(i, n) s ^= a[i];
    cout << (s^a[0]);
    for(int i=1; i<n; ++i) cout << " " << (s ^ a[i]);
    cout << endl;
}


Measured memory_bytes: 4012
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
    string s;
    cin >> s;
    string ans;
    rep(i,s.size()) {
        char c = s[i];
        if(c == '0') {
            ans += '0';
        } else if(c == '1') {
            ans += '1';
        } else {
            if(ans.size() != 0) {
                ans = ans.substr(0,ans.size()-1);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int i,j,n,point[200][3],tmp[3][100],p;
  for(j=0;j<100;j++)tmp[0][j]=0,tmp[1][j]=0,tmp[2][j]=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d",&point[i][0],&point[i][1],&point[i][2]);
    for(j=0;j<3;j++){
      tmp[j][point[i][j]-1]++;
    }
  }
  for(i=0;i<n;i++){
    for(j=0,p=0;j<3;j++){
      if(tmp[j][point[i][j]-1]==1){
	p+=point[i][j];
      }
    }
    printf("%d\n",p);
  }
  return 0;
}

Measured memory_bytes: 600
#include<cstdio>
const int N=1e5+10;
int a[N],n,m,T,k;
int main()
{
	scanf("%d%d%d",&n,&m,&T);
	for(int i=1;i<=T;i++)
	{
		scanf("%d",&k);
		a[k]++;
	}
	for(int i=1;i<=n;i++)
		if(m-T+a[i]<=0)puts("No");
		else puts("Yes");
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,m;std::cin>>n>>m;
    std::vector<std::vector<std::pair<lint,lint>>>g(n);
    while(m--){
        lint u,v,w;std::cin>>u>>v>>w;u--,v--;
        g.at(u).emplace_back(v,w);
        g.at(v).emplace_back(u,-w);
    }
    std::vector<lint>ckd(n),dp(n);
    auto dfs=[&](auto&&f,lint x)->void{
        for(auto&&e:g.at(x)){
            lint y,w;std::tie(y,w)=e;
            if(std::exchange(ckd.at(y),true)){
                if(dp.at(x)+w!=dp.at(y)){
                    std::cout<<"No"<<'\n';
                    exit(0);
                }
                continue;
            }
            dp.at(y)=dp.at(x)+w;
            f(f,y);
        }
    };
    for(lint i=0;i<n;i++){
        if(ckd.at(i))continue;
        dfs(dfs,i);
    }
    std::cout<<"Yes"<<'\n';
}


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

int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;

    int judge = 0, count = 0;

    rep (i, N) {
        if (judge == 2) {
            if (S.at(i) == 'C') {
                judge = 3;
                count++;
                continue;
            } else {
                judge = 0;
            }
        }
        if (judge == 1) {
            if (S.at(i) == 'B') {
                judge = 2;
                continue;
            } else {
                judge = 0;
            }
        }
        if (S.at(i) == 'A') {
            judge = 1;
            continue;
        } else {
            judge = 0;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> vec;
  rep(i, h){
    string str;
    cin >> str;
    vec.push_back(str);
  }
  rep(i, h){
    rep(j, w){
      if(vec[i][j] == '.') continue;
      else{
        bool found = false;
      	for (int x = -1, y = 0, k = 0; k < 4; x += y, y = x - y, x = y - x, ++k) {
   		  if((0 <= i+y) && (i+y < h) && (0 <= j+x) && (j+x < w)){
            if(vec[i+y][j+x] == '#'){
              found = true;
            }
          }
  		}
        if(!found){
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    hs = [int(x) for x in input().split()]
    ret = 0
    tmp = 0
    tmp_height = hs[0]
    for i in range(1, n):
        if hs[i] <= hs[i-1]:
            tmp += 1
        else:
            ret = max([ret, tmp])
            tmp = 0
    ret = max([ret, tmp])
    print(ret)
    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 14252
#include<cstdio>
#include<cstdlib>
#include<cstring>

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

Node *nil;

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

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

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

Node *searchNode(int key) {
	Node *n;
	for (n = nil->next; n != nil; n = n->next) {
		if (n->key == key) {
			break;
		}
	}
	return n;
}

void deleteKey(int key) {
	Node *delNode = searchNode(key);
	if (delNode == nil) return;
	delNode->prev->next = delNode->next;
	delNode->next->prev = delNode->prev;
	free(delNode);
}

void insert(int key) {
	Node *newNode = (Node *)malloc(sizeof(Node));

	newNode->key = key;

	nil->next->prev = newNode;
	newNode->next = nil->next;
	nil->next = newNode;
	newNode->prev = nil;
}

void printList() {
	bool isf = true;
	for (Node *n = nil->next;n != nil; n = n->next) {
		if (isf) {
			isf = false;
		}
		else {
			printf(" ");
		}
		printf("%d", n->key);
	}
	printf("\n");
}

int main() {
	int key, n, i;
	int size = 0;
	char com[30];
	scanf("%d", &n);
	init();

	for (i = 0; i < n; i++) {
		scanf("%s", com);
		if (com[0] == 'i') {
			scanf("%d", &key);
			insert(key);
		}
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				scanf("%d", &key);
				deleteKey(key);
			}
		}
	}
	printList();
	return 0;
}


Measured memory_bytes: 33932
N = int(input())
edge = [set() for i in range(N)]
for i in range(N-1): #辺の情報と距離を記録
  u, v, w = map(int, input().split())
  edge[u-1].add((v-1, w))
  edge[v-1].add((u-1, w))

#幅優先検索
dist = [0] * N #距離
stack = [0]
while stack: #stackが空になるまで
  vrt = stack.pop()
  for to, w in edge[vrt].copy():
    stack.append(to)
    dist[to] = dist[vrt] + w
    edge[vrt].discard((to, w))
    edge[to].discard((vrt, w))
    
for i in range(N):
  print(dist[i]%2)

Measured memory_bytes: 53644
#include <iostream>
#include <string>

using namespace std;

string s;
int z,o,c;

int main(){
    cin >> s;
    z = o = c = 0;
    for(int i=0;i<s.size();i++){
        if(s[i] == '0'){
            if(o > 0){
                c++;
                o--;
            }else{
                z++;
            }
        }else{
            if(z > 0){
                c++;
                z--;
            }else{
                o++;
            }
        }
    }
    cout << c*2 << endl;
    return 0;
}

Measured memory_bytes: 512
y=input()
# s=[[0 for i in range(m)] for j in range(n)]
# for i in range(n):
# 	s[i]=list(input())
 # SUN,MON,TUE,WED,THU,FRI,SAT
if y=='SUN':
	print(7)
elif y=='MON':
	print(6)
elif y=='TUE':
	print(5)
elif y=='WED':
	print(4)
elif y=='THU':
	print(3)
elif y=='FRI':
	print(2)
elif y=='SAT':
	print(1)


Measured memory_bytes: 2940
import collections
n = int(input())
a = list(map(int, input().split()))
b = [[0 for j in range(2)] for i in range(n)]
c = collections.Counter(a)
s = 0
for i in c:
	b[i-1][0] = c[i]*(c[i]-1)//2
	s += b[i-1][0]
	b[i-1][1] = (c[i]-1)*(c[i]-2)//2
for i in a:
	ans = s-b[i-1][0] + b[i-1][1]
	print (ans)

Measured memory_bytes: 45628