akhauriyash/Code-Regression huggingface dataset:
N,M = readline.chomp.split.map(&:to_i)

ary = []
left = M
money = 0
(1..N).each do |i|
  hash = {}
  a,b = readline.chomp.split.map(&:to_i)
  hash['a'] = a
  hash['b'] = b
  ary.push(hash)
end

# p ary

ary.sort_by! {|v| v['a'] }

# p ary

ary.each do |set|
  while((set['a'] > 0) && (set['b'] > 0)) do
    set['b'] -= 1
    left -= 1
    money += set['a']
    # p ary
    break if left == 0
  end
  break if left == 0
end

p money


Measured memory_bytes: 34680
N = int(input())
lst_T = input().split()
for i in range(len(lst_T)):
    lst_T[i] = int(lst_T[i])
M = int(input())

lst_D = []

for i in range(M):
    lst_D.append(input().split())
    lst_D[i][0] = int(lst_D[i][0])
    lst_D[i][1] = int(lst_D[i][1])

for i in range(M):
    W = lst_T[(lst_D[i][0])-1]
    lst_T[(lst_D[i][0])-1] = lst_D[i][1]
    print(sum(lst_T))
    lst_T[(lst_D[i][0]) - 1] = W

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	long long int n,a,b;
	long long int ab;
	cin >> n >> a >> b;
	ab = (n - (n % (a + b)))/(a + b);
	if(n % (a + b) > a){
		cout << (ab + 1) * a;
	}else{
		cout << ab * a + n % (a + b);
	}


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	char c;

	while (1) {
		scanf("%c", &c);
		if (c >= 'a' && c <= 'z')
			c = c - 32;
		else if (c >= 'A' && c <= 'Z')
			c = c + 32;
		putchar(c);

		if (c == '\n')
			break;
	}
	return 0;
}


Measured memory_bytes: 2100
#include <stdio.h>
 
main(){
  char map[10][10];
  int i, j,p=0,t;
 
  while(1){
    for(i=0;i<8;i++){
      for(j=0;j<8;j++){
    if(scanf("%c", &map[i][j])==EOF) p=1;
      }
      if(getchar()==EOF) p=1;
    }
    if(getchar()==EOF) p=1;
    if(p==1 && i<7 && j<7) break;
 
 
    t=0;
    for(i=0;i<8;i++){
      for(j=0;j<8;j++){
    if(map[i][j]=='1' && t==0){
      if(j<=6 && i<=6 ){
        if(map[i][j+1]=='1' && map[i+1][j]=='1' && map[i+1][j+1]=='1'){
          printf("A\n");
          t=1;
        }
      }
       
      if(j<=7 && i<=4 ){
        if(map[i+1][j]=='1' && map[i+2][j]=='1' && map[i+3][j]=='1'){
          printf("B\n");
          t=1;
        }
      }
       
      if(j<=4 && i<=7 ){
        if(map[i][j+1]=='1' && map[i][j+2]=='1' && map[i][j+3]=='1'){
          printf("C\n");
          t=1;
        }
      }
       
      if(j>=1 && j<=7 && i<=5 ){
        if(map[i+1][j-1]=='1' && map[i+1][j]=='1' && map[i+2][j-1]=='1'){
          printf("D\n");
          t=1;
        }
      }
       
      if(j<=5 && i<=6 && t==0){
        if(map[i][j+1]=='1' && map[i+1][j+1]=='1' && map[i+1][j+2]=='1'){
          printf("E\n");
          t=1;
        }
      }
       
      if(j<=6 && i<=5 ){
        if(map[i+1][j]=='1' && map[i+1][j+1]=='1' && map[i+2][j+1]=='1'){
          printf("F\n");
          t=1;
        }
      }
       
      if(j>=1 && j<=6 && i<=6 ){
        if(map[i][j+1]=='1' && map[i+1][j-1]=='1' && map[i+1][j]=='1'){
          printf("G\n");
          t=1;
        }
      }
    }
    if(t==1) break;
      }
      if(t==1) break;
    }
    if(p==1) break;
  }
  return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k%2)cout << b-a << endl;
    else cout << a-b << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 101
int p[N],m[N][N],n;

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

void matrix(void){
  int i,j,l,k;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i + l - 1;
      m[i][j] = 999999;
      for(k=i;k<=j-1;k++){
        m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  
  return;
}
                      
int main(){
  int i;  
  scanf("%d",&n);
   
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
  for(i=1;i<=n;i++)
    m[i][i] = 0;
    
  matrix();
  printf("%d\n",m[1][n]);
  
  return 0;
}


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

//関数
//main関数
int main() {
    
    
    //入力
    long N,W;
    cin>>N>>W;
    
    vector<long> w(N),v(N);
    for(int i=0;i<N;i++){
        cin>>w.at(i)>>v.at(i);
    }
    
    //計算
    vector<vector<long>> dp(N, vector<long>(W+1,0));
    for(int i=0;i<=W;i++){
        if(i<w.at(0)){
            dp.at(0).at(i)=0;
        }else{
            dp.at(0).at(i)=v.at(0);
        }
    }
    
    for(int n=1;n<N;n++){
        for(int i=0;i<=W;i++){
            if(i<w.at(n)){
                dp.at(n).at(i)=dp.at(n-1).at(i);
                
            }else{
                dp.at(n).at(i)=max(dp.at(n-1).at(i),dp.at(n-1).at(i-w.at(n))+v.at(n));
            }
        }
    }
    
    //出力
    cout<<dp.at(N-1).at(W)<<endl;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  int ans = 0, cnt = 1;
  FOR(i, 1, N+1) {
    if(a[i-1] != cnt) { ans++; }
    else { ++cnt; }
  }
  if(ans == N) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
using namespace std;
int main(void){
    ll N , Q ;
    cin >> N ;
    ll a[N] ;
    map<ll , ll> s ;
    ll ans = 0 ;
    rep(i , N){
        cin >> a[i] ;
        s[a[i]]++ ;
        ans += a[i] ;
    }
    cin >> Q ;
    ll b[Q] , c[Q] ;
    rep(j ,Q ){
        cin >> b[j] >> c[j] ;
    }
    rep(j ,Q ){
       ans += (c[j] - b[j])*s[b[j]] ;
       s[c[j]]+=s[b[j]] ;
       s[b[j]] = 0 ;
       cout << ans << endl;   
    }


    
    return 0;
}

Measured memory_bytes: 11884
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define fi first
#define se second
#define pb push_back
#define mp make_pair 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(i,a,b) for(int i = a; i <= b; i++)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define all(x) (x).begin(),(x).end()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using vvi = vector<vi>;
using vpi = vector<pii>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}
template<class T> bool uin(T &a, T b){ return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b){ return a < b ? (a = b, true) : false; }

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const int N = 100100;
ll mod=1000000007;
const ll oo = 9876543210;

vll operator*(const vll &a, const vll &b){
	vll ans(a.size());
	rep(i,a.size()){
		ans[i] = a[b[i]];	
	}
	return ans;
}

vll powe(vll a,ll k){
	vll ans(a.size());
	iota(ans.begin(),ans.end(),0);
	while( k > 0){
		if(k&1) ans = a*ans;
		a = a*a;
		k>>=1;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	startTime = clock();
	srand(time(0));
	ll n,k;
	cin>>n>>k;
	vll a(n+1);
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	vll ans = powe(a,k);
	cout<<ans[1]<<nl;
	return 0;
}



Measured memory_bytes: 9536
#include "bits/stdc++.h"
using namespace std;    

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))    
#define OUT(P) cout << (P) << endl    
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl    
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;    
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)    
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)    
typedef long long ll;    
const long DIVIDE = 1e9+7;

int sum_digits(int num);    
template <class T>    
vector<T> copy_vector(vector<T> vec);    
long gcd(long a, long b);    
long lcm(long a, long b);
vector<vector<long>> comb(long n, long r);
// ****** print functions ****** //
template <class T, class U>
void print_pairs(const vector<pair<T, U>> pairs);
template <class K, class V>
void print_map(const map<K, V> m);

int main() {    
    string s;
    cin >> s;
    int n = s.length();
    vector<long> prev(2019, 0);
	long cnt = 0;
    for(int i=1; i<=n; i++) {
        int num = s[i-1] - '0';
		vector<long> next(2019, 0);
        for(int j=0; j < 2019; j++) {
			next[(j * 10 + num) % 2019] = prev[j];
        }
		cnt += next[0];
		next[num]++;
		prev = next;
    }
    cout << cnt << endl;
    return 0;    
}    

/******************************/    
/***** DECRARED FUNCTIONS *****/    
/******************************/    

int sum_digits(int num) {    
    int rtn = 0;    
    while(num != 0) {    
        int tmp = num % 10;    
        rtn += tmp;    
        num /= 10;    
    }    
    return rtn;    
}    

// vectorのコピー    
template <class T>    
vector<T> copy_vector(vector<T> vec) {    
    vector<T> rtn;    
    rtn.reserve(vec.size());    
    copy(vec.begin(), vec.end(), back_inserter(rtn));    
    return rtn;    
}    

long gcd(long a, long b) {    
    if(b==0) return a;    
    else return gcd(b, a % b);    
}

long lcm(long a, long b) {
    long gcd_ = gcd(a, b);
    return (a * b) / gcd_;
}

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

template <class T, class U>
void print_pairs(const vector<pair<T, U>> &pairs) {
    for(int i=0; i<pairs.size(); i++) { 
        cout << "(" << pairs[i].first << ", " << pairs[i].second << ")" << " "; 
    } 
    cout << endl;
}

template <class K, class V>
void print_map(const map<K, V> &m) {
    for(auto it=m.cbegin(); it!=m.cend(); it++) {
        cout << it->first << ": " << it->second << endl;
    }
}


Measured memory_bytes: 3700
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const K = parseInt(arg[0].split(" ")[0]);
    const N = parseInt(arg[0].split(" ")[1]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    
    let distances = []
    
    // 区間を作る
    for(let i=0; i<N; i++) {
        let distance;
        
        if(parseInt(i) === N - 1) {
            distance = (K - A[i]) + A[0];
        } else {
            distance = A[parseInt(i) + 1] - A[i];
        }
        
        distances.push(distance);
    }
    
    const sum = distances.reduce((m,n)=>m+n);
    let answer = sum - distances.sort((a,b)=>b-a)[0];
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    int N;
    string S;
    cin >> N >> S;
    int red = 0, blue = 0;
    REP(i, N) {
        if(S[i] == 'R') { red++; }
        else { blue++; }
    }
    printf("%s\n", (red > blue) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cout << a[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		cout << " " << a[i];
	}
	cout << endl;

}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します



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

int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;

  reverse(sa.begin(), sa.end());
  reverse(sb.begin(), sb.end());
  reverse(sc.begin(), sc.end());

  char person = 'a';
  char winner = 'A';
  while(true) {
    if(person == 'a') {
      if(sa.size() == 0) {
        winner = 'A';
        break;
      }
      person = sa[sa.size()-1];
      sa.pop_back();
    } else if(person == 'b') {
      if(sb.size() == 0) {
        winner = 'B';
        break;
      }
      person = sb[sb.size()-1];
      sb.pop_back();
    } else {
      if(sc.size() == 0) {
        winner = 'C';
        break;
      }
      person = sc[sc.size()-1];
      sc.pop_back();
    }
  }

  cout << winner << endl;
}

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

using namespace std;


int main (){
  int k, x;

  cin >> k >> x;
  cin.ignore();

  for (int i = x - (k - 1); i <= x + (k - 1); i++){
    cout << i << " " << flush;
  }
  cout << endl;
  return 0;
  
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
count = 0

flag = 1
while flag:
    flag = 0
    for j in range(1, n):
        num = a[j]
        if a[j] < a[j-1]:
            a[j] = a[j-1]
            a[j-1] = num
            count += 1
            flag = 1

print(*a, sep=' ')
print(count)


Measured memory_bytes: 5600
/*
33
ABCCABCBABCCABACBCBBABCBCBCBCABCB
*/
#include <bits/stdc++.h>
using namespace std;
void print() { cout << '\n'; } template<class T, class ...U> void print(T x, U ...y){ cout << x << ' '; print(y...); }
typedef long long ll; const int N = 2e5 + 5, M = 1e9 + 7; typedef vector<int> vi; typedef vector<vi> vii; void Main();
int main(int argc, char **argv) {
  ios::sync_with_stdio(0), cin.tie(0); cout << setprecision(10) << fixed;
  #ifdef Zmm
  freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x;
  #endif
  Main();
}

void Main() {
  int n, ans = 0;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
  }
  print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;//角度转弧度 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 1e3+10;

int main() {
	double a, b, h, m;
	cin>>a>>b>>h>>m;
	double ang = abs(5.0 * (h + m / 60.0) - m) * 6.0;
	double ang1 = 360 - ang;
	printf("%.29f\n", sqrt(a * a + b * b - 2.0 * a * b * cos(min(ang, ang1) * epsilon)));
	return 0;
}

Measured memory_bytes: 4120
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
adj = [[] for _ in range(n)]
for i in range(m):
	a,b = list(map(int,input().split()))
	adj[a-1].append(b-1)
	adj[b-1].append(a-1)
visited = {}
for j in range(n):
	visited[j] = 0
c = 0
for i in range(n):
	if visited[i] == 0:
		f = 0
		for j in adj[i]:
			if h[j] < h[i]:
				visited[j] = 1
			else:
				f = 1
		if f == 0:
			c += 1
		visited[i] = 1
print(c)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}

int N,K;

signed main(){
    cin>>N>>K;

    vint ei;
    for(int i=1;i*i<=N;i++){
        if(N%i)continue;
        ei.pb(i);
        if(i*i!=N)ei.pb(N/i);
    }

    sort(all(ei));
    vint dp(ei.size());
    int ans=0;
    for(int i=0;i<ei.size();i++){
        dp[i]=mpow(K,(ei[i]+1)/2);
        for(int j=0;j<i;j++)if(ei[i]%ei[j]==0)dp[i]=(dp[i]-dp[j]+mod)%mod;
        if(ei[i]%2)ans=(ans+dp[i]*ei[i])%mod;
        else ans=(ans+dp[i]*ei[i]/2)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ls = list(map(int,input().split()))

count = 0

for i in range(n):
  if ls[i] == i+1:
    continue
  else:
    count +=1
    if count >=2:
      break
    if ls[ls[i]-1]==i+1:
      ls[ls[i]-1] = ls[i]
      ls[i] = i+1

    else:
      count+=1

if count>=2:
  print("NO")
else:
  print("YES")


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
#define double long double
using namespace std; const int N=200010, Mod1=19260817, Mod2=998244353, Mod3=1e9+7;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n,m,book[N],f1[N],f2[N],f3[N];
int head[N],maxE; struct Edge{ int nxt,to,w1,w2,w3; }e[N];
inline void Add(int u,int v,int z1,int z2,int z3)
{
    e[++maxE].nxt=head[u]; head[u]=maxE; e[maxE].to=v;
    e[maxE].w1=z1, e[maxE].w2=z2, e[maxE].w3=z3;
}
inline int ksc(int x,int p,int Mod) { int res=1; for(;p;p>>=1, x=x*x%Mod) if(p&1ll) res=res*x%Mod; return res; }
void DFS(int x,int fa)
{
    book[x]=1;
    for(int i=head[x];i;i=e[i].nxt)
    {
        if(e[i].to==fa) continue;
        if(book[e[i].to])
        {
            int a=f1[x]*e[i].w1%Mod1*ksc(f1[e[i].to],Mod1-2,Mod1)%Mod1;
            int b=f2[x]*e[i].w2%Mod2*ksc(f2[e[i].to],Mod2-2,Mod2)%Mod2;
            int c=f3[x]*e[i].w3%Mod3*ksc(f3[e[i].to],Mod3-2,Mod3)%Mod3;
            if( (a^1ll) || (b^1ll) || (c^1ll) ) { puts("No"); exit(0); }
        }
        else
        {
            f1[e[i].to]=f1[x]*e[i].w1%Mod1;
            f2[e[i].to]=f2[x]*e[i].w2%Mod2;
            f3[e[i].to]=f3[x]*e[i].w3%Mod3;
            DFS(e[i].to,x);
        }
    }
}
signed main()
{
    n=read(), m=read();
    for(ri int i=1;i<=n;i++) f1[i]=f2[i]=f3[i]=1;
    for(ri int i=1;i<=m;i++)
    {
        int u,v,w;
        u=read(), v=read(), w=read();
        Add(u,v,w%Mod1,w%Mod2,w%Mod3);
        Add(v,u,ksc(w,Mod1-2,Mod1),ksc(w,Mod2-2,Mod2),ksc(w,Mod3-2,Mod3));
    }
    for(ri int i=1;i<=n;i++) if(!book[i]) DFS(i,0);
    puts("Yes");
    return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	char C; cin >> C;

	if(C >= 'A' and C <= 'Z') cout << 'A' << endl;
	else cout << 'a' << endl;


	return 0;

}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
long long cnt = 0;
long long dfs(long long f, int a, int b, int c){
	if (f <= N){
		if (a&&b&&c){
			cnt++;
		}
	}
	else return 0;
	dfs(f * 10 + 7, 1, b, c);
	dfs(f * 10 + 5, a, 1, c);
	dfs(f * 10 + 3, a, b, 1);
	return cnt;
}
int main(){
	cin >> N;
	cout << dfs(0, 0, 0, 0) << endl;
	return 0;
}


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

typedef pair<long long, int> pli;

const int N = 1e5 + 10;
int h[N], n, cnt[N], par[N];
long long d[N], check;
vector<pli> di;
vector<int> child[N];
map<long long, int> mp;

void dfs(int v, int p){
	h[v] = h[p] + 1;
	for (int u : child[v])
		dfs(u, v);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> d[i];
		di.push_back({d[i], i});
		mp[d[i]] = i + 1;
	}
	
	sort(di.begin(), di.end());
	reverse(di.begin(), di.end());
	
	for (int i = 0; i < n; i++)
		cnt[i] = 1;
	for (int i = 0; i < n - 1; i++){
		int v = di[i].second;
		long long dis = di[i].first,
				  par_dis = dis + (2 * cnt[v]) - n;
		
		if(mp[par_dis] == 0)
			return cout << -1, 0;
		
		int ver_par = mp[par_dis] - 1;
		cnt[ver_par] += cnt[v];
		par[v] = ver_par;
		child[par[v]].push_back(v);
	}
	
	int root = di[n - 1].second;
	h[root] = -1;
	par[root] = root;
	dfs(root, root);
	
	for (int i = 0; i < n; i++)
		check += h[i];
	
	if(check != d[root])
		return cout << -1, 0;
	
	for (int i = 0; i < n; i++)
		if(par[i] != i)
			cout << par[i] + 1 << ' ' << i + 1 << endl;
}

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

namespace AGC005_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine();
            var ans = x.Length;
            var G = new Stack<int>();
            for (int i = 0; i < x.Length; i++)
            {
                if(x[i] == 'S')
                {
                    G.Push(i);
                }

                else if(G.Any())
                {
                    ans -= 2;
                    G.Pop();
                }
                /*if(x[i] == 'T' && x[i-1] == 'S' )
                {
                    ans -= 2;
                    i++;
                }*/
            }

            Console.WriteLine(ans);
        }
    }
}


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

namespace ConsoleApp11
{
    class Class32
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var P = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var Q = P.OrderBy(x => x).ToArray();
            int count = 0;
            for (int i = 0; i < P.Count(); i++)
            {
                if (P[i] != Q[i])
                    count += 1;
            }
            Console.WriteLine(count < 3 ? "YES" : "NO");    
        }
    }
}


Measured memory_bytes: 13396
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int A, B; cin >> A >> B;
    int ans = 0;
    for (int i = A; i <= B; i++)if (i % 10 == i / 10000 && i % 100 / 10 == i % 10000 / 1000)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin >> K >> N;
    int A[N];
    int maxD=0;
    cin >> A[0];
    for(int i=1; i<N; i++){
        cin >> A[i];
        maxD = max(maxD,A[i]-A[i-1]);
    }
    maxD=max(maxD,A[0]+K-A[N-1]);
    cout << K-maxD;
    return 0;
}

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

int main()
{
	stringstream ss;
    // 入力
    int N,M;
    cin>>N>>M;
    int a[M],b[M];
    int i,j,k;
    for(i=0;i<M;i++){
        a[i]=0;
        b[i]=0;
    	cin>>a[i]>>b[i];
    }

    // 定義通り、M本それぞれについて、それを取り除いて非連結になるか考える。
    // 非連結性を見るため、つながっている2つの点は同じ点だと思ってグラフデータを書き直す。
    int bridge_num=0;
    int a_temp[M],b_temp[M];
    int b_original=0;
    int point_id[N];
    for(k=0;k<M;k++){
        //cout<<"graph-"<<k<<endl;
        for(i=0;i<M;i++){
            a_temp[i]=a[i];
            b_temp[i]=b[i];
        }
        for(j=0;j<N;j++){
            point_id[j]=j+1;
        }
        b_temp[k]=a_temp[k];
        for(i=0;i<M;i++){
            // cout<<a[i]<<b[i]<<endl;
            //cout<<a_temp[i]<<b_temp[i]<<endl<<endl;
            b_original=b_temp[i];
            for(j=0;j<N;j++){
                if(point_id[j]==b_original) point_id[j]=a_temp[i];
            }
            for(j=0;j<M;j++){
                if(a_temp[j]==b_original) a_temp[j]=a_temp[i];
                if(b_temp[j]==b_original) b_temp[j]=a_temp[i];
            
            }
        }
        for(i=0;i<N;i++){
            //cout<<point_id[i]<<endl;
            if(point_id[i]!=point_id[0]) {
                //cout<<"not connected!"<<endl;
                bridge_num++;
                break;
            }
            // cout<<a_temp[i]<<b_temp[i]<<endl;
        }
    }
    cout<<bridge_num<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int calc(int x, int y, int b, int p) {
    int money = x * b + y * p;
    if (b >= 5 && p >= 2) {
        money *= 0.8;
    }
    return money;
}

int main() {
    int n, x, y, b, p, v1, v2;
    cin >> n;
    while (n--) {
        cin >> x >> y >> b >> p;
        v1 = calc(x, y, b, p);
        if (b >= 5 && p >= 2) {
            cout << v1 << endl;
        }
        else {
            if (b < 5 && p < 2) {
                v2 = calc(x, y, 5, 2);
            }
            else if (b < 5) {
                v2 = calc(x, y, 5, p);
            }
            else {
                v2 = calc(x, y, b, 2);
            }
            
            if (v1 > v2) {
                cout << v2 << endl;
            }
            else {
                cout << v1 << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int A, B, C;
int main()
{
	cin >> A >> B >> C;
	while (A > 100 || A < -100 || B>100 || B < -100 || C>100 || C < -100)
		cin >> A >> B >> C;
	if (A == B)
		cout << C << endl;
	else if (B == C)
		cout << A << endl;
	else if (A == C)
		cout << B << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sumvec(vector<S>&a){return accumulate(all(a),S());}
template<class S>S maxvec(vector<S>&a){return *max_element(all(a));}
template<class S>S minvec(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}


int main(void){
  	cin.tie(0);
  	ios::sync_with_stdio(false);
    
    ll h,w,n;
    string s;
    cin>>h>>w>>n;
    ll big=(h>w)?h:w;
    ll ans=n/big;
    if(n%big!=0) ans++;
    puta(ans);
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define INIT_CAP 10
#define INF 1000000000

#define min(a, b) (((a) < (b)) ? (a) : (b))

const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, 1, 0, -1};

typedef struct {
	int to, w;
} Edge;

typedef struct {
	Edge *elem;
	int cap, size;
} VecEdge;

typedef struct {
	int num, d;
} PNumDis;

VecEdge adj[30 * 30 * 4];
PNumDis heap[30 * 30 * 4 * 4];
int hsize;
int d[30 * 30 * 4];

int w, h;
int field[30][30];

void init(int n) {
	while (n--)
		adj[n] = (VecEdge){malloc(sizeof(Edge) * INIT_CAP), INIT_CAP, 0};
}

void add(int from, int to, int w) {
	if (adj[from].size == adj[from].cap) {
		adj[from].cap <<= 1;
		adj[from].elem = realloc(adj[from].elem, sizeof(Edge) * adj[from].cap);
	}
	adj[from].elem[adj[from].size++] = (Edge){to, w};
}

void freeAll(int n) {
	while (n--)
		free(adj[n].elem);
}

void insert(int num, int d) {
	int i;
	for (i = hsize++; i > 0 && d < heap[i - 1 >> 1].d; i = i - 1 >> 1)
		heap[i] = heap[i - 1 >> 1];
	heap[i] = (PNumDis){num, d};
}

int calcNextIdx(int i) {
	return i * 2 + 1 + (i * 2 + 2 < hsize && heap[i * 2 + 1].d > heap[i * 2 + 2].d);
}

PNumDis delete(void) {
	int i;
	int nextIdx;
	const PNumDis root = heap[0], last = heap[--hsize];

	for (i = 0; i * 2 + 1 < hsize && last.d > heap[nextIdx = calcNextIdx(i)].d; i = nextIdx)
		heap[i] = heap[nextIdx];
	heap[i] = last;

	return root;
}

void dijkstra(int n, int s) {
	int i;

	for (i = 0; i < n; i++)
		d[i] = INF;

	d[s] = 0;
	insert(s, 0);
	while (hsize > 0) {
		const PNumDis fromP = delete();

		if (fromP.d > d[fromP.num])
			continue;

		// if (field[fromP.num / 4 / w][fromP.num / 4 % w] == 4)
		// 	continue;

		for (i = 0; i < adj[fromP.num].size; i++) {
			const Edge e = adj[fromP.num].elem[i];
			if (fromP.d + e.w < d[e.to]) {
				d[e.to] = fromP.d + e.w;
				insert(e.to, d[e.to]);
			}
		}
	}
}

int main(void) {
	int i, j, k, l;

	while (scanf("%d %d", &w, &h), w) {
		int c[4];

		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				scanf("%d", field[i] + j);

		for (i = 0; i < 4; i++)
			scanf("%d", c + i);

		init(h * w * 4);

		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				for (k = 0; k < 4; k++)
					for (l = 0; l < 4; l++) {
						int nd = k + l & 3;
						int ni = i + di[nd], nj = j + dj[nd];
						if (ni >= 0 && ni < h && nj >= 0 && nj < w)
							add(i * w * 4 + j * 4 + k, ni * w * 4 + nj * 4 + nd, l == field[i][j] ? 0 : c[l]);
					}

		dijkstra(h * w * 4, 1);

		printf("%d\n", min(d[(h - 1) * w * 4 + (w - 1) * 4 + 1], d[(h - 1) * w * 4 + (w - 1) * 4 + 2]));

		freeAll(h * w * 4);
	}

	return 0;
}

Measured memory_bytes: 1036
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <numeric>
#include <bitset>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
long long INF = 1e10;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/******************************define*********************************/

/*****************************functions********************************/

/****************************main function*****************************/
int main(void) {

	long long R; cin >> R;
	long long G; cin >> G;
	long long B; cin >> B;
	long long N; cin >> N;
	ll count = 0;
	for (int i = 0; i <= N / R; i++) {
		for (int j = 0; j <= (N - i * R) / G; j++) {
			if ((N - i * R - j * G) % B == 0) count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 384
#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; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll a[n], b[n];
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];

  ll res = 0, sum = 0, d;
  
  REP(i, n){
    d = b[i] - a[i];
    if(d > 0){
      sum += (d + 1) / 2;
      res += d % 2;
    }
    else res += -d;
  }
  if(sum >= res) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using CompLib.Util;

public class Program
{
    private int N;
    private int[] A, B;

    public void Solve()
    {
        var sc = new Scanner();

        N = sc.NextInt();
        A = sc.IntArray();
        B = sc.IntArray();

        // 使わなきゃいけない数
        List<int> l = new List<int>();
        long ans = 0;
        for (int i = 49; i >= 0; i--)
        {
            // 集合の最大値 l以外
            bool[,] f = new bool[51, 51];
            for (int j = 0; j <= 50; j++)
            {
                foreach (int k in l)
                {
                    f[j, j % k] = true;
                }

                for (int k = i; k >= 1; k--)
                {
                    f[j, j % k] = true;
                }

                f[j, j] = true;
            }

            for (int j = 0; j <= 50; j++)
            {
                for (int k = 0; k <= 50; k++)
                {
                    for (int m = 0; m <= 50; m++)
                    {
                        f[k, m] |= f[k, j] && f[j, m];
                    }
                }
            }

            bool ff = true;
            for (int j = 0; j < N; j++)
            {
                if (!f[A[j], B[j]])
                {
                    ff = false;
                    break;
                }
            }

            if (!ff)
            {
                if (i == 49)
                {
                    Console.WriteLine("-1");
                    return;
                }

                l.Add(i + 1);
                ans |= 1L << (i + 1);
            }
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

ll i,j,k,l;


int main(){
    ll n;cin>>n;
    vector<ll> a(n),b(n),c(n);

    vector<ll> counterB(n+1,0),counterC(n+1,0);

    for(i=0;i<n;i++){cin>>a[i];}

    ll ans=0;
    
    for(i=0;i<n;i++){
        b[i]=a[i]+i;
        c[i]=i-a[i];
        if(b[i]<=n) counterB[b[i]]++;
        if(c[i]>=0) counterC[c[i]]++;
    }


    for(i=0;i<n+1;i++){
        ans+=counterB[i]*counterC[i];
    }

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

Measured memory_bytes: 11176
#include <stdio.h>
 
int main(void){
   
   int i,j;
   int input_num;
   
   scanf("%d",&input_num);
   
   int L[input_num];
   
   for(i = 0;i < input_num ; i++)
     scanf("%d",&L[i]);
    
   int L_max = 0;
   int L_sum = 0;
   for(j = 0; j < input_num; j++){
     if(L_max < L[j])
       L_max = L[j];
                     
       L_sum += L[j];
   }

  int judge;
  judge = L_sum - L_max;
  
   if(L_max < judge)
     printf("Yes");
                   
   else 
     printf("No");
   return 0;
}

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

int partition(int A[],int p,int r){
  int x,i,tmp;
  x=A[r-1];
  i=p-1;
  for(int j=p;j<=r-2;j++){
    if(A[j]<=x){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
     }
    }
  tmp=A[i+1];
  A[i+1]=A[r-1];
  A[r-1]=tmp;
  return i+1;
}

int main(){
  int n,m;
  cin>>n;
  int S[n];
  for(int i=0;i<n;i++){
    cin>>S[i];
  }
  m=partition(S,0,n);
  for(int i=0;i<m;i++){
    cout<<S[i]<<' ';
  }
  cout<<'['<<S[m]<<']';
  for(int i=m+1;i<n;i++){
    cout<<' '<<S[i];
  }
  cout<<endl;
}



Measured memory_bytes: 3360
#include<bits/stdc++.h>
using namespace std;
const int SIZE=25*25;

int di[]={1,1,-1,-1};
int dj[]={1,-1,-1,1};
int inii[]={-1,0,1,0};
int inij[]={0,1,0,-1};
int solve(int m,int n,int d){
    vector<bitset<SIZE>> bits(m*n);
    vector<vector<int>> s(n,vector<int>(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>s[i][j];
        }
    }
    auto getV=[&](int i,int j){
        return i*m+j;
    };
    auto isRange=[&](int i,int j){
        return 0<=i && i<n && 0<=j && j<m;
    };
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            bits[getV(i,j)][getV(i,j)]=true;
            for(int dir=0;dir<4;dir++){
                for(int k=0;k<d;k++){
                    int toi=i+inii[dir]*d+di[dir]*k;
                    int toj=j+inij[dir]*d+dj[dir]*k;
                    if(isRange(toi,toj)){
                        bits[getV(i,j)][getV(toi,toj)]=true;
                    }
                }
            }
        }
    }
    vector<int> flag(m*n);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            flag[getV(i,j)]=s[i][j];
        }
    }
    int sz=n*m;
    int row=0;
    int col=0;
    while(row<sz && col<sz){
        int pivot=-1;
        for(int j=row;j<sz;j++){
            if(bits[j][col]){
                pivot=j;
                break;
            }
        }
        if(pivot==-1){
            col++;
            continue;
        }
        else{
            swap(bits[row],bits[pivot]);
            swap(flag[row],flag[pivot]);
            for(int i=0;i<sz;i++){
                if(i!=row && bits[i][col]){
                    bits[i]^=bits[row];
                    flag[i]^=flag[row];
                }
            }
            row++,col++;
        }
    }
    for(int i=0;i<sz;i++){
        if(bits[i]==0 && flag[i]){
            return false;
        }
    }
    return true;
}
int main(){
    int m,n,d;
    while(cin>>m>>n>>d,m){
        cout<<solve(m,n,d)<<endl;        
    }
    return 0;
}


Measured memory_bytes: 3208
n = int(input())
s = [int(input()) for _ in range(n)]
b = []
if sum(s) % 10 != 0:
    print(sum(s))
else:
    for i in s:
        if i % 10 != 0:
            b.append(i)

    print(sum(s) - min(b) if len(b) > 0 else 0)


Measured memory_bytes: 2940
#include <cstdio>

long Left(long i) {
    return 2 * i;
}

long Right(long i) {
    return (2 * i + 1);
}

void MaxHeapify(long A[], int size, int i) {
    int l = Left(i + 1) - 1;
    int r = Right(i + 1) - 1;
    int largest = i;
    if ( l < size && A[i] < A[l]) largest = l;
    if ( r < size && A[largest] < A[r]) largest = r;
    if (largest != i) {
        int tmp = A[i]; A[i] = A[largest]; A[largest] = tmp;
        MaxHeapify(A, size, largest);
    }

}

void BuildMaxHeap(long A[], int size) {
    for (int i=(size/2-1); 0<=i; i--) {
        MaxHeapify(A, size, i);
    }
}

int main() {
    int H;
    scanf("%d", &H);
    long A[H];
    for (int i=0; i<H; i++) scanf("%ld", &A[i]);

    BuildMaxHeap(A, H);
    for (int i=0; i<H; i++) printf(" %ld", A[i]);
    printf("\n");
}

Measured memory_bytes: 4932
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

ll roundUp(double x)
{
	ll y = x;

	double z = x - (double)y;
	
	if(z != 0)
		return y + 1;
	else 
		return y;
}

int main()
{
	ll a,b, ans = -1;
	double a1, b1;
	ll a2,b2;
	string s;

	cin >> a >> b;

	a1 = roundUp((double)a * 12.5);
	a2 = roundUp(((double)(a+1) * 12.5));

	b1 = roundUp((double)b * 10);
	b2 = roundUp(((double)(b+1) * 10));

	if (a1 > b1)
	{
		if (a1 < b2)
			ans = a1;
	}
	else
	{
		if (b1 < a2)
			ans = b1;
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def solve(H: int):
    ans=len(str(bin(H)))-2
    print(2**ans-1)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    solve(H)

if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using db = double;
#define pb push_back

const int mxn = 306;
const ll mod = 1E9+7;
const int MXL = 0x3f3f3f3f;

int n, m;
ll f[mxn][mxn][mxn];
int mn[mxn][4];
int mx[mxn][4];

bool check(int i, int j, int k) {
	#define ass(x) ({if(!(x))return false;})
	ass(j < mn[i][1]);
	ass(k < mn[i][2] && mx[i][2] <= j);
	ass(mx[i][3] <= k);
	
	return true;
}

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= 3; ++j) {
			mn[i][j] = MXL;
			mx[i][j] = -MXL;
		}
	for (int i = 0; i < m; ++i) {
		int l, r, w;
		cin >> l >> r >> w;
		mn[r][w] = min(mn[r][w], l);
		mx[r][w] = max(mx[r][w], l);
	}
	
	f[1][0][0] = 3 % mod;
	
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j < i; ++j)
			for (int k = 0; k < j || k == 0; ++k) {
				if (check(i, j, k)) {
					(f[i + 1][j][k] += f[i][j][k]) %= mod;
					(f[i + 1][i][k] += f[i][j][k]) %= mod;
					(f[i + 1][i][j] += f[i][j][k]) %= mod;
				} else {
					f[i][j][k] = 0;
				}
			}
	
	ll ans = 0;
	
	int i = n;
	for (int j = 0; j < i; ++j)
		for (int k = 0; k < j || k == 0; ++k)
			(ans += f[i][j][k]) %= mod;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 219392
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String b=sc.next();
    if(b.charAt(0)=='A') System.out.println("T");
    if(b.charAt(0)=='T') System.out.println("A");
    if(b.charAt(0)=='C') System.out.println("G");
    if(b.charAt(0)=='G') System.out.println("C");

  }
}


Measured memory_bytes: 23252
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
#include <queue>
#include <functional>
using namespace std;
int main()
{	
	long long int x, y, yan = 0;
	char a[55][55], b[55][55];
	cin >> x >> y;
	for (int i = 1; i <= x; i++) {
		for (int j = 1; j <= x; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= y; i++) {
		for (int j = 1; j <= y; j++) {
			cin >> b[i][j];
		}
	}
	for (int i = 1; i <= x-y+1; i++) {
		for (int j = 1; j <= x-y+1; j++) {
			if (a[i][j] == b[1][1]) {
				for (int k = 1; k <= y; k++) {
					for (int l = 1; l <= y; l++) {
						if (a[i + k - 1][j + l - 1] != b[k][l]) {
							yan = 1;
							break;
						}
					}
					if (yan) {
						break;
					}
				}
				if (!yan) {
					cout << "Yes" << endl;
					return 0;
				}
				yan = 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
int n,m,sum=0;
int a[1001],b[1001];
cin >> n >> m;
for(int i=0;i<m;i++){
cin >> a[i] >> b[i];
}
sort(a,a+m);
for(int i=1;i<m;i++){
if(n<=a[i]){
break;
}
sum+=n-a[i];
}
cout << sum << endl;
return 0;
}


Measured memory_bytes: 3156