akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(ll size) {
        size = max((int) sqrt(size) + 1, 101010);
        prime.resize(size, 1);
        prime[0] = 0;
        prime[1] = 0;
        for (size_t i = 2; i * i <= size; ++i)
            if (prime[i]) {
                for (size_t j = 2; i * j <= size; ++j)prime[i * j] = false;
            }
    }
};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};


ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll K, A, B;

int main() {
    cin >> K >> A >> B;
    if (B - A < 3 || K < A + 1) {
        cout << K + 1 << endl;
        return 0;
    }
    ll res = B;
    K -= A + 1;
    res += (B - A) * (K / 2);
    res += K % 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
  int m, n;
  cin >> m >> n;

  int max = 0;
  for (int i = 0; i < m; i++) {
    int count = 0;
    for (int j = 0; j < n; j++) {
      int x;
      cin >> x;
      count += x;
    }
    if (count > max)
      max = count;
  }

  cout << max << endl;
  return 0;
}

Measured memory_bytes: 1164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Arrays;

public class Main {

	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	
	public static void main(String args[]) throws IOException {
		int n = getInt();
		int d[] = new int[n];
		for ( int i = 0 ; i < n ; i++ ) {
			d[i] = getInt();
		}
		Arrays.sort(d);
		System.out.println(d[n/2]-d[n/2-1]);
	}
}


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


long double a, b, x, ans;

#define PI 3.14159265358979323846

int main() {
	cin >> a >> b >> x;

	if (x * 2 >= (a * a * b)) {
		cerr << "1" << endl;
		ans = atan((a * a * a) / (2 * (b * a * a - x)));
	} else {
		cerr << "2" << endl;
		ans = atan((2 * x) / (a * b * b));
	}
	printf("%.10Lf\n", 90 - (ans * 180) / PI );

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define ld long double


int main(){

int x,a,b,c;
cin>>a>>b>>c>>x;

int count=0;
for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
        for(int k=0;k<=c;k++){
            if(i*500 + j*100 +k*50 ==x)
                count++;
        }
    }
}

cout<<count;
}

Measured memory_bytes: 3156
import numpy as np
N = int(input())
a, b = 0, 0
for i in np.arange(np.floor(np.sqrt(N)), 0, -1):
    c = N/i
    if c.is_integer():
        a = int(i)
        break
b = int(N/a)
print(a+b-2)

Measured memory_bytes: 20164
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 998244353;
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  int n;
  F f;
  G g;
  T d1;
  E d0;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int n_,F f,G g,T d1,
	      vector<T> v=vector<T>()):
    f(f),g(g),d1(d1){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  void update(int k,E a){
    k+=n-1;
    dat[k]=g(dat[k],a);
    while(k>0){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
  inline T query(int a,int b){
    T vl=d1,vr=d1;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[(l++)-1]);
      if(r&1) vr=f(dat[(--r)-1],vr);
    }
    return f(vl,vr);
  }
  
};
     signed main(){
      int n;
      cin>>n;
      pair<int,int>p[n];
      int k;
      for(int i=0;i<n;i++){
         cin>>k;
         p[i]={k,i};
      }
      sort(p,p+n);
       SegmentTree<int,int> rmq(n+2,
			   [](int a,int b){return a+b;},
			   [](int a,int b){return b;},
			   0);
            int ans=0;
      for(int i=n-1;i>=0;i--){
         int l2,l1,r1,r2,ok,ng,mid,j=p[i].second;
         ok=-1;ng=p[i].second;
         while(abs(ok-ng)>1){
            mid=(ok+ng)/2;
            if(rmq.query(mid,j)>=2)ok=mid;
            else ng=mid;
         }
         l2=ok;
          ok=-1;ng=p[i].second;
         while(abs(ok-ng)>1){
            mid=(ok+ng)/2;
            if(rmq.query(mid,j)>=1)ok=mid;
            else ng=mid;
         }
         l1=ok;
          ng=n+1;ok=p[i].second;
         while(abs(ok-ng)>1){
            mid=(ok+ng)/2;
            if(rmq.query(j,mid)==0)ok=mid;
            else ng=mid;
         }
         r1=ok;
            ng=n+1;ok=p[i].second;
         while(abs(ok-ng)>1){
            mid=(ok+ng)/2;
            if(rmq.query(j,mid)<=1)ok=mid;
            else ng=mid;
         }
         r2=ok;
         ans+=p[i].first*((l1-l2)*(r1-j)+(j-l1)*(r2-r1));
         rmq.update(j,1);

      }
      cout<<ans<<endl;


     }


 


 






    





      

        


Measured memory_bytes: 6936
import fractions
from functools import reduce
N, X = map(int, input().split())
listx = list(map(int, input().split()))
subx = []
for i in range(N):
  subx.append(abs(listx[i] - X))
  
def lcm_list(numbers):
    return reduce(fractions.gcd, numbers)

ans = lcm_list(subx)

print(ans)

Measured memory_bytes: 88852
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std; 
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n;cin>>n;
	int count1=0; int count2=0;
	int ans=0;int count3=0;ll ans1=0;
	for(int i=0;i<n;i++){
		string s;cin>>s;
		for(int i=0;i<s.length()-1;i++){
			if(s[i]=='A' && s[i+1]=='B'){
				ans1++;
			}
		}
		if(s[0]=='B' && s[s.length()-1]!='A'){
			count2++;
		}
		if(s[0]!='B' && s[s.length()-1]=='A'){
			count1++;
		}
		if(s[0]=='B' && s[s.length()-1]=='A'){
			count3++;
		}
	}	
	ans += max(0,count3-1);
	if(ans>0 || count3>0){
		if(count1>0){
			ans++;count1--;
		}
		if(count2>0){
			ans++; count2--;
		}
	}
	ans += min(count1,count2);
	cout<<ans1+ans<<endl;
}


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

using namespace std;

#define ll 			long long
#define db			double
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cadd(a,b)		a = add (a, b)
#define cpop(a,b)		a = pop (a, b)
#define cmul(a,b)		a = mul (a, b)
#define pr			pair<int, int>
#define fi			first
#define se			second
#define SZ(x)		(int)x.size()
#define bin(i)		(1 << (i))
#define Auto(i,node)	for (int i = LINK[node]; i; i = e[i].next)

template<typename T> inline bool cmax(T & x, T y){return y > x ? x = y, true : false;}
template<typename T> inline bool cmin(T & x, T y){return y < x ? x = y, true : false;}

const int MAXN = 5005;
const int MAXM = MAXN * 5;

string ss[MAXM], s;
int K, cnt;

int main(){
	cin >> s >> K;
	int len = s.length();
	up (i, 0, len - 1) up (j, i, min(i + K - 1, len - 1)) 
		ss[++cnt] = s.substr(i, j - i + 1);
	sort(ss + 1, ss + cnt + 1);
	cnt = unique(ss + 1, ss + cnt + 1) - ss - 1;
	cout << ss[K] << endl; 
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main(){
  // モンスターの数, 必殺技の回数
  int N, K; cin >> N >> K;
  
  // N体のモンスターの体力
  vector<long long> HP(N);
  for (long long& x: HP) cin >> x;

  sort(HP.begin(), HP.end(), greater<long long>());
  
  // HPが高い敵をK体倒す
  for (auto itr = HP.begin(); (itr < (HP.begin()+min(K, N))); ++itr){
    *itr = 0;
  }
  
  // 何回攻撃すれば勝てるか
  long long cnt = 0;
  for (long long x: HP) cnt+=x;
  
  cout << cnt << endl;

}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;

    for (;;) {
        int n, m; cin >> n >> m;
        if (!n && !m) break;

        vector<int> v(n);
        rep(i, 0, n) cin >> v[i];
        sort(all(v));

        int best = -1;

        int l = 0, r = n - 1;
        for (; l < n; l++) {
            while (r >= 0 && v[l] + v[r] > m) r--;
            if (l >= r) break;
            best = max(best, v[l] + v[r]);
        }

        if (best == -1) cout << "NONE" << endl; else cout << best << endl;
    }

}


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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll ans = 0;
  rep(i, N) {
    if (i % 2 == 0) ans += A[i];
    if (i % 2 == 1) ans -= A[i];
  }
  cout << ans << " ";
  for (int i = 0; i < N-1; i++) {
    int a = A[i];
    ans = -(ans -2*a);
    cout << ans << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> a(N);

  for (int i = 0; i < N; i++) std::cin >> a[i];

  int button_currently_shining = 1; // 1-based
  int tmp_button;
  int push_count = 0;
  bool exists_two = false;

  while (true) {
    if (button_currently_shining == -1) {
      break;
    } else if (button_currently_shining == 2) {
      exists_two = true;
      break;
    } else {
      tmp_button = button_currently_shining;
      button_currently_shining = a[button_currently_shining - 1];
      a[tmp_button - 1] = -1;
      ++push_count;
    }
  }
  if (exists_two) {
    std::cout << push_count << std::endl;
  } else {
    std::cout << -1 << std::endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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;
}

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a,b,k;
  cin>>a>>b>>k;
  if(k<=a){
    cout<<a-k<<' '<<b<<endl;
  }else if(k<=a+b){
    cout<<0<<' '<<b-k+a<<endl;
  }else{
    cout<<"0 0"<<endl;
  }
}


Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    if (n <= 599) cout << 8;
    else if (n <= 799) cout << 7;
    else if (n <= 999) cout << 6;
    else if (n <= 1199) cout << 5;
    else if (n <= 1399) cout << 4;
    else if (n <= 1599) cout << 3;
    else if (n <= 1799) cout << 2;
    else if (n <= 1999) cout << 1;
    return 0;
}


Measured memory_bytes: 3656
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

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

    for(int j = N-1;j>=1;j--)
    {
        if(H[j-1] > H[j])
        {
            H[j-1]--;
        }
        if(H[j-1] > H[j])
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout << "Yes" <<endl;
    
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>


typedef long long ll;

using namespace std;

int main() 
{ 

	map<int, int> cnt;

	int n;
	cin >> n;


	for (int i = 0; i < n-1; i++){
		int temp;
		cin >> temp;
		cnt[temp]++;
	}

	for (int i = 1; i <= n; i++){
		cout << cnt[i] << endl;
	}

	return 0; 
} 


Measured memory_bytes: 13008
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int count = 0;
	string s; cin >> s;
	rep(i,3)if(s[i]=='1') count++;
	cout << count << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <stack>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
#define ll long long
static const int MAX = 100010;
static const ll INFTY = 1e12;
static const int NUMMAX = 300;



int main() {

  string S;
  ll maxdai=0, maxsyo=0;
  ll ans = 0;

  cin >> S;

  REP(i, S.length()){
    if(S[i]=='<'){
      if( maxsyo != 0 ){
        ans += ( max( maxdai, maxsyo ) + 1 ) * max( maxdai, maxsyo ) / 2;
        ans += ( min( maxdai, maxsyo ) + 1 ) * min( maxdai, maxsyo ) / 2;
        ans -=min( maxdai, maxsyo );
      //  cout << maxdai << " " << maxsyo << " " << ans << endl;
        maxsyo = 0;
        maxdai=0;
      }
      maxdai++;
    }
    if(S[i]=='>'){
      maxsyo++;
    }
  }
    if( maxsyo != 0 || maxdai != 0 ){
      ans += ( max( maxdai, maxsyo ) + 1 ) * max( maxdai, maxsyo ) / 2;
      ans += ( min( maxdai, maxsyo ) + 1 ) * min( maxdai, maxsyo ) / 2;
      ans -=min( maxdai, maxsyo );
    //  cout << maxdai << " " << maxsyo << endl;
    }

  cout << ans << endl;
 
  return 0;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 900
from collections import*
n,m=map(int,input().split())
outs=defaultdict(list)
ins=defaultdict(int)
for _ in range(m):
    a,b=map(int,input().split())
    outs[a-1]+=b-1,
    ins[b-1]+=1
q=deque(i for i in range(n)if ins[i]==0)
res=[]
while q:
    v=q.popleft()
    res+=v,
    for w in outs[v]:
        ins[w]-=1
        if ins[w]==0:
            q.append(w)
print(-(len(res)==n))

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

constexpr int MAX = 1e9;

class tree {
    tree *left = nullptr, *right = nullptr;
    int count = 0;
    long long sum = 0;
public:
    void add(int x, int l = -MAX, int r = MAX+1) {
        count++; sum += x;
        if (r - l > 1) {
            if ((l + r) / 2 > x) {
                if (left == nullptr) left = new tree();
                left->add(x, l, (l + r) / 2);
            } else {
                if (right == nullptr) right = new tree();
                right->add(x, (l + r) / 2, r);
            }
        }
    }
    int getnth(int n, int l = -MAX, int r = MAX+1) {
        if (r - l == 1) return l;
        if (left == nullptr) return right->getnth(n, (l+r)/2, r);
        else if (right == nullptr) return left->getnth(n, l, (l+r)/2);
        else if (left->count > n) return left->getnth(n, l, (l+r)/2);
        else return right->getnth(n - left->count, (l+r)/2, r);
    }
    long long getsum(int n, int l = -MAX, int r = MAX+1) {
        if (r - l == 1) return (long long)l * n;
        if (left == nullptr) return right->getsum(n, (l+r)/2, r);
        else if (right == nullptr) return left->getsum(n, l, (l+r)/2);
        else if (left->count > n) return left->getsum(n, l, (l+r)/2);
        else return left->sum + right->getsum(n - left->count, (l+r)/2, r);
    }
};

int main() {
    int q; cin >> q;
    long long A = 0, B = 0;
    int n = 0;
    tree t;
    while (q--) {
        int k; cin >> k;
        if (k == 1) {
            int a, b; cin >> a >> b;
            B += b;
            A += a;
            n++;
            t.add(a);
        } else {
            int m = (n-1)/2;
            long long am = t.getnth(m);
            long long s = t.getsum(m);
            // cerr << m << ' ' << am << ' ' << s << endl;
            cout << am << ' ' << am * (2*m-n) + A - 2 * s + B << endl;
        }
    }
}


Measured memory_bytes: 74880
import math


def lcm(x, y):
    return x * y // math.gcd(x, y)


def main():
    n = int(input())
    t_lst = [int(input()) for _ in range(n)]
    t_lst.sort()
    answer = t_lst[0]
    for i in range(1, n):
        t = t_lst[i]
        answer = lcm(answer, t)

    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 8888
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define RR 5009
int b[233][RR];
int n,m; ll a[RR],qzh[RR][RR];
inline void add(int x1,int y1,int x2,int y2,ll v)
{
	++x2; ++y2;
	qzh[x1][y1]+=v; qzh[x2][y2]+=v;
	qzh[x1][y2]-=v; qzh[x2][y1]-=v;
}
int L[5555],R[5555];
void work(int*x)
{
	static int st[5555]; int sn=0;
	for(int i=1;i<=n;++i)
	{
		while(sn&&x[st[sn]]<=x[i]) --sn;
		L[i]=st[sn]+1; st[++sn]=i;
	}
	sn=0;
	for(int i=n;i>=1;--i)
	{
		while(sn&&x[st[sn]]<x[i]) --sn;
		R[i]=sn?(st[sn]-1):n; st[++sn]=i;
	}
	for(int i=1;i<=n;++i)
		add(L[i],i,i,R[i],x[i]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=2;i<=n;++i)
		scanf("%lld",a+i),a[i]+=a[i-1];
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			scanf("%d",&b[j][i]);
	for(int j=1;j<=m;++j) work(b[j]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			qzh[i][j]+=qzh[i][j-1]+qzh[i-1][j]-qzh[i-1][j-1];
	ll ans=0;
	for(int i=1;i<=n;++i)
		for(int j=i;j<=n;++j)
		{
			ll s=qzh[i][j]-(a[j]-a[i]);
			ans=max(ans,s);
		}
	printf("%lld\n",ans);
}

Measured memory_bytes: 200192
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi()
    d = {}
    for i, accum in enumerate(a):
        d[accum] = i + 1
    for j in range(1, n+1):
        print(d[j], end=' ')
    print('')

if __name__ == "__main__":
    main()

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

const int N = 100054, mod = 1000000007;

int n;
int f[N], S[N];
char s[N];

inline void add(int &x, const int y) {x += y - mod, x += x >> 31 & mod;}

int main() {
	int i, B[3] = {1}; bool flag = false;
	scanf("%s", s), n = strlen(s);
	for (i = 1; i < n && s[i] != s[i - 1]; ++i);
	if (i == n) return puts("1"), 0;
	for (*f = i = 1; i <= n; ++i)
		S[i] = (S[i - 1] + s[i - 1]) % 3, f[i] = f[i - 1] + !S[i],
		add(f[i], B[S[i] ^ S[i - 1] ^ 3]), B[S[i]] = f[i];
	if (!S[n]) add(f[n], mod - 1);
	printf("%d\n", f[n]);
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> l(n), r(n);
	rep(i, n-1) l[i+1] = gcd(l[i], a[i]);
	for (int i = n-1; i >= 1; i--) {
		r[i-1] = gcd(r[i], a[i]);
	}
	int ans = 1;
	rep(i, n) ans = max(ans, gcd(l[i], r[i]));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;


int abc104_c(){
    //入力
    int n;
    cin >> n;
    string a[n];
    map<string,int> mpa;
    REP(i,0,n){
        cin >> a[i];
        mpa[a[i]]++;
    }
    int m;
    cin >> m;
    string b[m];
    map<string,int> mpb;
    REP(i,0,m){
        cin >> b[i];
        mpb[b[i]]++;
    }
    int ans = 0;

    //処理
    for(auto itr = mpa.begin(); itr != mpa.end(); ++itr){
        auto check = itr->first;
        ans = max(ans,mpa[check]-mpb[check]);
    }

    //出力
    cout << ans << ENT;
    return 0;
}

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


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

using Data = pair < string , int >;

int main()
{
        string S = "         ";
        queue < Data > que;
        set < string > used;
        int d[4] = {-3, -1, 1, 3};

        for ( int i = 0; i < 9; i++ ) cin >> S[i];
        
        que.emplace(S, 0);

        while ( !que.empty() ) {
                Data q = que.front(); que.pop();
                string T;
                if ( q.first == "123456780" ) {
                        cout << q.second << endl;
                        return ( 0 );
                }
                int pos = q.first.find('0');
                for ( int i = 0; i < 4; i++ ) {
                        int npos = pos + d[i];
                        string T = q.first;
                        if ( i == 1 && pos % 3 == 0 ) continue;
                        if ( i == 2 && pos % 3 == 2 ) continue;
                        if ( npos < 0 || 8 < npos ) continue;
                        swap(T[pos], T[npos]);
                        if ( used.find(T) == used.end() ) {
                                used.insert(T);
                                que.emplace(T, q.second + 1);
                        }
                }
        }

        return ( 0 );
}



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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  vector<int> L(N), R(N), oL(N), oR(N);
  // vector<bool> done(N);
  for (int i = 0; i < N; i++) cin >> L.at(i) >> R.at(i);
  iota(oL.begin(), oL.end(), 0);
  iota(oR.begin(), oR.end(), 0);
  sort(oL.begin(), oL.end(), [&](int i, int j) { return L.at(i) > L.at(j); });
  sort(oR.begin(), oR.end(), [&](int i, int j) { return R.at(i) < R.at(j); });
  ll K1 = 0;
  int cur = 0;
  {
    int pos = L.at(oL.at(0));
    if (pos > 0) {
      cur = K1 = pos;
    }
  }
  int idx = 0;
  while (true) {
    int pos = R.at(oR.at(idx));
    if (cur <= pos) break;
    K1 += cur - pos;
    cur = pos;
    idx++;
    pos = L.at(oL.at(idx));
    if (pos <= cur) break;
    K1 += pos - cur;
    cur = pos;
  }
  K1 += abs(cur);
  ll K2 = 0;
  cur = 0;
  {
    int pos = R.at(oR.at(0));
    if (pos < 0) {
      cur = pos;
      K2 = -cur;
    }
  }
  idx = 0;
  while (true) {
    int pos = L.at(oL.at(idx));
    if (pos <= cur) break;
    K2 += pos - cur;
    cur = pos;
    idx++;
    pos = R.at(oR.at(idx));
    if (cur <= pos) break;
    K2 += cur - pos;
    cur = pos;
  }
  K2 += abs(cur);
  ll K = max(K1, K2);
  cout << K << endl;
  return 0;
}



Measured memory_bytes: 1920
#include <iostream>
#include <cmath>
#include <limits>

using namespace std;


int main(){
    long long A, B, N;
    cin >> A >> B >> N;
    long long  Y = 0;
    long long  Ans = 0;
    if(N >= B) 
     Ans = floor(A*(B-1)/B) - A * floor((B-1)/B);
    else if(N < B)
     Ans = floor(A*(N)/B) - A * floor(N/B);
    
    cout << Ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, l;
    string a[200];
    cin>>n>>l;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++) cout<<a[i];
    return 0;
}


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

void merge(int *,int,int,int);
void mergeSort(int *,int,int);
int *L,*R,cnt=0;

int main(){
  int n,S[500000],i;
    scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
 
  mergeSort(S,0,n);

  for(i=0;i<n;i++){
    printf("%d",S[i]);
    if(i<n-1) printf(" ");
  }
  printf("\n%d\n",cnt);
   

  return 0;
}

void merge(int *S,int left,int mid,int right){
  int n1,n2,i,k,j;
  n1 = mid - left;
  n2 = right - mid;
  L=(int *)malloc((n1+1)*sizeof(int));
  R=(int *)malloc((n2+1)*sizeof(int));
  
  for(i=0;i<n1;i++) L[i] = S[left + i];
  for(i=0;i<n2;i++) R[i] = S[mid + i];
  L[n1]=N;
  R[n2]=N;
  i = 0;
  j = 0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i] <= R[j]){
      S[k] = L[i];
      i=i+1;
    }else{
	S[k]=R[j];
	j=j+1;
    }
  }

}



void mergeSort(int *S,int left,int right){
  int mid;
  if(left+1<right){
    mid = (left + right)/2;
    mergeSort(S,left,mid);
    mergeSort(S,mid,right);
    merge(S,left,mid,right);
  }

}



Measured memory_bytes: 64508
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P


int main(){
	long long A,B,C;
	long long K;
	scanf("%lld %lld %lld", &A, &B, &C);

	scanf("%lld", &K);

	if(K%2==1){
		printf("%lld\n", B-A);
	}else{
		printf("%lld\n", A-B);
	}


	return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int a = sc.nextInt();
        String op = sc.next();
        int b = sc.nextInt();

        int ans;

        if (op.equals("+")) {
            ans = a + b;
        } else {
            ans = a - b;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;
  vector<pair<int, ll> > cb(m);
  for (int i = 0; i < m; i++) cin >> cb[i].second >> cb[i].first;

  sort(a.begin(), a.end());
  sort(cb.rbegin(), cb.rend());

  int p = 0;
  int q = 0;
  int r = cb[0].second;
  while (true) {
    if (a[p] < cb[q].first) {
      a[p] = cb[q].first;
      p++;
      if (p >= n) break;
      r--;
      if (r <= 0) {
        q++;
        if (q >= m) break;
        r = cb[q].second;
      }
    }
    else break;
  }

  ll ans = 0;
  for (auto &x: a) ans += x;

  cout << ans << endl;

  return 0;
}


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

int distance(int x1, int y1, int x2, int y2)
{
    return abs(x1 - x2) + abs(y1 - y2);
}

int main()
{
    int N, x[100], y[100], h[100];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }
    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            int H = 0;
            for (int i = 0; i < N; i++) {
                if (h[i] != 0) {
                    H = h[i] + distance(cx, cy, x[i], y[i]);
                    break;
                }
            }
            for (int i = 0; i < N; i++) {
                int cal_h = max(H - distance(cx, cy, x[i], y[i]), 0);
                if (h[i] != cal_h) goto NEXT;
            }
            cout << cx << " " << cy << " " << H << endl;
            return 0;
            NEXT:;
        }
    }
    return 0;
}

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

#define ll long long int

using namespace std;

ll a,b,k;

int main(){
    scanf("%lld %lld %lld",&a,&b,&k);

    ll res1 = max((ll) 0,a-k);
    if(res1 > 0) printf("%lld %lld\n",res1 ,b);
    else{
        printf("0 %lld\n",max(b-abs(a-k),(ll)0));
    }
}


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

int main(){
    int n,p;

    while(cin>>n>>p,n|p){
        int c=p;
        int res;
        vector<int> v(n,0);
        for(int i=0;i<n;i++){
            if(c>0){
                if(++v[i] == p){
                    res=i;
                    break;
                }
                c--;
            }else{
                c+=v[i];
                v[i]=0;
            }
            if(i==n-1) i=-1;
        }

        cout << res << endl;
    }
}

Measured memory_bytes: 1196
process.stdin.resume()
process.stdin.setEncoding('utf8')
var g_input = ''
process.stdin.on('data', function(chunk) {
    g_input += chunk
})
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/))
})
function main(input){
  console.log(input[0]<30 ? 'No' : 'Yes')
}

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

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

	vector< int > vec( a );

	for( auto &it : vec )
	{
		cin >> it;
	}

	sort( vec.begin(), vec.end(), greater<int>() );

	int alice = 0;
	int bob = 0;


	int cnt = 0;


	for( auto &it : vec )
	{
		if( cnt & 1 )	bob += it;
		else			alice += it;		
		cnt++;
	}





	cout << ( alice - bob ) << endl;

	return 0;
}

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


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    UF.union(a, b)
UF.all_find()

print(max(UF.size))


Measured memory_bytes: 20208
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define MEM(a, x) memset(a, x, sizeof a)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template<typename T> void dbg(T &x) {cerr << x << endl;}
template<typename T> void dbga(T &x, int &n) {for(int i = 0; i < n; i++) {cerr << i << ": "; cerr << x[i] << endl;} }
template<typename T> void dbgv(T &x) {bool first = true; cerr << "{"; for(auto i : x) {if(!first) cerr << ","; cerr << i; first = false;} cerr << "}" << endl;}

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

	int n;
	string s;

	cin >> n >> s;

	if(n&1)
		cout << "No" << endl;
	else {
		for(int i = 0; i < n/2; i++) {
			if(s[i] != s[n/2 + i]) {
				cout << "No" << endl;
				return 0;
			}
		}

		cout << "Yes" << endl;
	}	

	return 0;
}

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

int main(){
    int N;
    scanf("%d",&N);
    if(N % 2 == 1){
        N -= 1;
        printf("%d",N/2+1);
    }else{
        printf("%d",N/2);
    }
    return 0;
}

Measured memory_bytes: 128
#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()
{
	int n, m, x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> v(n, vector<int>(m));
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> v[i][j];
        }
    }
    ll ans = 1e18;
    for(int bit = 0; bit < (1 << n); bit++){
        ll sum = 0;
        vector<ll> t(m, 0);
        for(int i = 0; i < n; i++){
            if(bit & (1 << i)){
                sum += c[i];
                for(int j = 0; j < m; j++){
                    t[j] += v[i][j];
                }
            }
        }
        bool f = true;
        for(int i = 0; i < m; i++){
            if(t[i] < x)f = false;
        }
        if(f){
            ans = min(ans, sum);
        }
    }
    if(ans == 1e18)cout << -1 << endl;
    else cout << ans << endl;
    system("pause");
}


Measured memory_bytes: 3692
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	vvll light(m,vll(0)) ;
	for(int i=0;i<m;i++){
		ll a ; cin >> a ;
		for(int j=0;j<a;j++){
			ll b ; cin >> b ;
			b-- ;
			light.at(i).push_back(b) ;
		}
	}
	vll p(m,0) ;
	for(int i=0;i<m;i++) cin >> p.at(i) ;
	ll ans = 0 ;
	for(int i=0;i<(1<<n);i++){
		bitset<20> bit(i) ;
		bool ok = true ;
		for(int j=0;j<m;j++){
			ll cnt = 0 ;
			for(int k=0;k<light.at(j).size();k++){
				if(bit[light.at(j).at(k)]) cnt++ ;
			}
			if(cnt%2!=p.at(j)) ok = false ;
		}
		ans += ok ;
	}
	cout << ans << endl ;
}



Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=5005;
char s[N];int f[N][N],n,res;
int main(){
	scanf("%d%s",&n,s+1);
	fp(i,1,n)fp(j,i+1,n){
		f[i][j]=(s[i]==s[j])?min(f[i-1][j-1]+1,j-i):0;
		cmax(res,f[i][j]);
	}
	printf("%d\n",res);
	return 0;
}

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

int main() {
	int N, C;
	cin >> N >> C;
	vector<vector<int>> d(C, vector<int>(C));
	vector<vector<int>> c(N, vector<int>(N));
	vector<vector<int>> data(3, vector<int>(C));
	for (int i = 0; i < C; ++i) {
		for (int j = 0; j < C; ++j) {
			cin >> d[i][j];
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> c[i][j];
			data[(i + j) % 3][c[i][j]-1]++;
		}
	}
	long long ans = 1e18;
	for (int i = 0; i < C; ++i) {
		for (int j = 0; j < C; ++j) {
			for (int k = 0; k < C; ++k) {
				long long anstmp = 0;
				if (i == j) {
					continue;
				}
				if (j == k) {
					continue;
				}
				if (i == k) {
					continue;
				}
				//cout << i << j<<k << endl;
				for (int l = 0; l < C; ++l) {
					anstmp += d[l][i] * data[0][l];
				}
				for (int l = 0; l < C; ++l) {
					anstmp += d[l][j] * data[1][l];
				}
				for (int l = 0; l < C; ++l) {
					anstmp += d[l][k] * data[2][l];
				}
				ans = min(ans ,anstmp);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4532
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.nextLine();

        if(Integer.parseInt(a.substring(5,7))<=4 && Integer.parseInt(a.substring(8,10)) <=30){
            System.out.println("Heisei");
        }else{
            System.out.println("TBD");
        }
        
    }

}


Measured memory_bytes: 21588
#include<stdio.h>
void Selection(int *x,int *y){
    int v;
    v = *x;
    *x = *y;
    *y = v;
}
int main(){
    int N;
    int i,j,minj;
    int count=0;
    scanf("%d",&N);
    int A[N];
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    for(i=0;i<=N-1;i++){
        minj=i;
        for(j=i;j<=N-1;j++){
            if(A[j]<A[minj]){
                minj=j;
            }
        }
            if(A[i]!=A[minj]){
                Selection(&A[i],&A[minj]);
                count++;
            }
    }
    for(i=0;i<N-1;i++){
        printf("%d ",A[i]);
    }
    printf("%d\n",A[N-1]);
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2068
#include <iostream>
#include <iomanip>
#include <array>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <numeric>
#include <cassert>
#include <functional>
using namespace std;

typedef unsigned long long int llui;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
constexpr double pi = 3.141592653589793238462643383279502884L;

// TODO: Mod class

const int sz = 1e5;

int main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  if (n == 1 || m == 1) {
    if (n == 1 && m == 1) {
      cout << 1 << endl;
    } else {
      cout << n * m - 2 << endl;
    }
  } else {
    cout << n * m - (2 * n + 2 * m - 4) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int k;
  string s;
  cin >> k >> s;
  int m = s.size();
  for (int i = 0; i < min(k, m); ++i) {
    cout << s.at(i);
  }
  if (m > k) {
    cout << "...";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

const int mod = 1e9+7;
#define ll long long int
const double epsilon = 1e-7;

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}
ll dp[101][10];
//dp[i][j] は高さiを通った後に
//j番目の線にいるときの場合の数をmodで割った値

int br[] = {1, 1, 1, 2, 3, 5, 8, 13, 21, 34};

int main(void){
    int h, w, k;
    scanf("%d %d %d", &h, &w, &k);
    for(int j = 0;j < w+2;j++){
        dp[0][j] = 0;
    }
    for(int i = 0;i < h;i++){
        dp[i][0] = 0;
        dp[i][w+1] = 0;
    }
    dp[0][1] = 1;
    for(int i = 0;i < h;i++){
        for(int j = 1;j < w+1;j++){
            dp[i+1][j] = (dp[i][j-1]*br[j-1]*br[w-j+1] + dp[i][j]*br[j]*br[w-j+1] + dp[i][j+1]*br[j]*br[w-j])%mod;
        }
    }
    printf("%lld\n", dp[h][k]);
    return 0;
}

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

n_katamari = 1

for i in range(n-1):
	if string[i] != string[i+1]:
		n_katamari += 1

n_katamari -= 2 * k
if n_katamari < 1:
	n_katamari = 1 

print(n - n_katamari)


Measured memory_bytes: 3316