akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <numeric>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define ALL(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

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

ll lcm(ll number1,ll number2){
	return number1 * number2 / gcd(number1,number2);
}



int main(){
	ll a, b, c, d; cin >> a >> b >> c >> d;
	ll ans = 0;
	ll x, y, z;
	// cout << "LCM" << endl;
	ll l = lcm(c,d);
	// cout << l << endl;
	x = b/c - (a-1)/c;
	y = b/d - (a-1)/d;
	z = b/l - (a-1)/l;
	ans = (b-a+1) - (x+y-z);


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
	 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back
#define M int(1e9+7)
#define endl '\n'
	
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;

int main(){
	fast_io; cout_precision;
	int r;	cin >> r;	cout << 3.14159*r*2 <<endl;
}


Measured memory_bytes: 3800
#include <stdlib.h>

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

main()
{
	int N;
    int A[100000];
    int i,j,k,l,m,n;
    scanf("%d",&N);
    for (i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    m=1;
     qsort(A, N, sizeof(int), compare_int);
   for(j=0;j<=N-2;j++){
   	if(A[j+1]>A[j])
   	m+=1;
}
if(m%2==1)
printf("%d",m);
else
printf("%d",m-1);
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n; cin>>n;
	rep(h,n){
		int y,m,d; cin>>y>>m>>d;
		long ans=0;
		if(y%3==0){
			ans+=(10-m)*20+21-d;
		}else{
			if(m%2==0){
				ans+=(10-m)/2*39+(20-d);
			}else{
				ans+=(10-m)/2*39+(40-d);
			}
			if(y%3==1){
				ans+=395; y+=2;
			}else{
				ans+=200; y++;
			}
		}
		ans+=(999-y)/3*590;
		cout<<ans<<endl;
	}
	return 0;
}



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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int m = 1000005;
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<int>count(m);
    for (int x : a) {
        if (count[x] != 0) {
            count[x] = 2;
            continue;
        }
        for (int i = 0; i < m; i += x) count[i]++; 
    }
    int ans = 0;
    for (int x : a) {
        if (count[x] == 1) ans++;
    } 
    cout << ans << endl;
    return 0;
}

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

public class Main {
  private static int solve(int a, int b, String op) {
    if (op.equals("+")) {
      return a + b;
    } else {
      return a - b;
    }
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    String op = reader.next();
    int b = reader.nextInt();
    out.println(solve(a, b, op));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 23124
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  vector<long long> input;
  long long N;
  long long a;
  scanf("%lld", &N);
  for(long long i=0;i<N;i++){
    scanf("%lld", &a);
    input.push_back(a);
  }
  vector<long long> forward_sum(N);
  vector<long long> backward_sum(N);
  forward_sum[0]=input[0];
  //backward_sum[N-1]=input[N-1];
  for(long long i=1;i<N;i++){
    forward_sum[i]=input[i]+forward_sum[i-1];
    //backward_sum[N-1-i]=input[N-1-i]+backward_sum[N-i];
  }
  forward_sum.push_back(0);
  // long long total=forward_sum[N-1];
  long long ans=0;
  vector<long long> sorted=vector<long long>(forward_sum);
  std::sort(sorted.begin(), sorted.end());
  long long prev=sorted[0];
  long long count=1;
  long long last=0;
  for(long long i=1;i<N+1;i++){
    if(prev==sorted[i]){
      count++;
      continue;
    }
    else{
      ans+=count*(count-1)/2;
      count=1;
      prev=sorted[i];
      last=i;
    }
  }
  // if(last!=N)
  ans+=count*(count-1)/2;
  printf("\n%lld", ans);
}

Measured memory_bytes: 8176
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  ll n,m;
  cin >> n >> m;
  UnionFind tree(n);
  vector<ll>a(m);
  vector<ll>b(m);
  vector<ll>ans(m);
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  ans[m-1]=n*(n-1)/2;
  for(ll i=m-1;i>=1;i--){
    if(tree.issame(a[i],b[i]))ans[i-1]=ans[i];
    else{
      ll cnt=0;
      cnt=tree.size(a[i])*tree.size(b[i]);
      ans[i-1]=ans[i]-cnt;
      tree.merge(a[i],b[i]);
    }
  }
  rep(i,m) cout << ans[i] << endl;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const ll inf = 1LL<<60;

int main()
{
  int n; cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int mi = n+1;
  int ans = 0;
  rep(i, n) {
    if (mi > p[i]) ans++;
    mi = min(mi, p[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
	ll x;
	cin>>x;
	return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 
 
vector <vector <int> > g;
vector <int> val;
vector <int> a;
 int dfs(vector <bool> &visited,int s);
 vector <int> test;
  vector <int> ans;
  void rerooting(int s,vector <bool> &visited);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll r=nxtl(),c=nxtl();
    if(r==1||c==1)
    {
        cout<<"1\n";
        return 0;
    }
    ll test=r*c;
    if(test%2==0)
        test/=2;
    else{
         test=((r*(c-1))/2)+r/2+r%2;
         
    }
    cout<<test<<endl;

    return 0;   
}


 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A,A+3);
  cout << A[2] - A[0] << endl;
  return 0;
    

}


Measured memory_bytes: 256
def main():
    N = int(input())
    NN = [[0]*10 for _ in range(11)]
    for i in range(11,100):
        As = str(i)[0]
        Ae = str(i)[-1]
        cnt = 0
        for j in range(1,N+1):
            if str(j)[-1]== As and str(j)[0] == Ae:
                cnt +=1
        NN[int(As)][int(Ae)] = cnt


    ans = 0
    for i in range(1,N+1):
        ans += NN[int(str(i)[0])][int(str(i)[-1])]

    print(ans)

if __name__ == '__main__':
        main()



Measured memory_bytes: 73420
N, Y = list(map(int, input().split()))

xres, yres, zres = -1, -1, -1
flag = False
for x in range(0, N + 1):
  y = 0
  while (x + y) <= N:
    z = N - (x + y)
    if (10 * x + 5 * y + z) == Y / 1000:
      flag = True
      xres, yres, zres = x, y, z
      break
    y += 1
  if flag:
    break

print(xres, yres, zres)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin>>a>>b;
  if(a<b){
    for(int i=0;i<b;i++)
      cout<<a;
  }
  else{
    for(int i=0;i<a;i++)
      cout<<b;
  }
  cout<<"\n";
}

Measured memory_bytes: 256
d=[1]+[0]*12
for c in input():
	e=[0]*13
	for k in([c],range(10))[c>'9']:
		for j in range(13):t=(j*10+int(k))%13;e[t]+=d[j];e[t]%=10**9+7
	d=e
print(d[5])

Measured memory_bytes: 44848
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::string s; std::cin >> s;
  int da[4], db[4];
  da[1] = db[0] = da[3] = db[3] = -1;
  da[0] = db[1] = 1;
  int a0 = 0, b0 = 0, a1 = -1, b1 = -1, ma = 0, mb = 0;
  for(int i = 0; i < s.size(); ++i) {
    char c = s[i];
    ma += da[c&3]; if(ma < 0) ma = 0;
    mb += db[c&3]; if(mb < 0) mb = 0;
    if(i&1) {
      a0 = std::max(a0, ma);
      b0 = std::max(b0, mb);
    } else {
      a1 = std::max(a1, ma);
      b1 = std::max(b1, mb);
    }
  }
  ma = std::max(a0, a1); if(a0 == a1) ++ma;
  mb = std::max(b0, b1); if(b0 == b1) ++mb;
  fin(std::max(ma, mb));
  return 0;
}


Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, S);
  ll ans = 0;
  int s = S.length();
  rep(i, 1, s + 1) {
    rep(j, 0, s - i + 1) {
      ll val = stoll(S.substr(j, i));
      int t = pow(2, max(j - 1, 0) + max(s - (j + i) - 1, 0));
      ans += val * t;
    }
  }

  print(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,count=0,min=200000;
  string s;
  cin >>n;
  vector<int> v;
  char pc='F';
  
  rep(i,n){
    char c;
    cin >>c;
    if(pc==c||pc=='F'){
      count++;
    }else{
      if(v.size()>0||c=='R')v.push_back(count);
      count=1;
    }
    pc=c;
  }
  v.push_back(count);
  if(v.size()%2==1)v.pop_back();
  if(v.size()==0){
    cout <<0;
    return 0;
  }
  
  rep(i,v.size()/2+1){
    int wc=0,rc=0;
    rep(j,v.size()/2){
      if(j<i)wc+=v[2*j];
      else rc+=v[2*j+1];
    }
    if(min>max(wc,rc))min=max(wc,rc);
  }
  //rep(i,v.size())cout <<v[i];
  cout <<min;
}

Measured memory_bytes: 3792
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll w[200500], n, m, v, p;
inline bool check(ll e)
{
	if (e >= n-p) return true;
	ll t = (p-1)*m;
	for(ll i = 0; i+p <= n; i++)
	{
		if (min(m, w[e]+m-w[i]) < 0) return false;
		t+=min(m, w[e]+m-w[i]);
	}
	return t >= m*v;
}
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>v>>p;
	for(int i = 0; i < n; i++) cin>>w[i];
	sort(w, w+n);
	ll cnt = 0, l = -1, r = n;
	while(r-l > 1)
	{
		int mid = (l+r)/2;
		if (check(mid)) r = mid;
		else l = mid;
	}
	cout<<n-r;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priotity_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ld PI=abs(acos(-1));
ll n,a,A;

int main(){
	cin >> n >> A;
	
	ll dp[5010][55];
	REP(i,0,5010) REP(j,0,55) dp[i][j]=0;
	dp[0][0]=1;
	REP(i,0,n){
		cin >> a;
		RREP(j,5000,0){
			REP(k,0,n){
				if(dp[j][k] and j+a<5010) dp[j+a][k+1]+=dp[j][k];
			}
		}
	}
	
	ll c=0;
	REP(i,1,n+1) if(i*A<5000 and dp[i*A][i]) c+=dp[i*A][i];
		
	cout << c << endl;
	return 0;
}


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



int main() {
    int n;
    cin >> n;
    
    vector<int> a(n),b(n),c(n-1);
    rep(i,n) {
        cin >> a[i];
        a[i]--;
    }
    rep(i,n) {
        cin >> b[i];
    }
    rep(i,n-1) {
        cin >> c[i];
    }
    
    int sum = 0;
    rep(i,n-1) {
        sum += b[a[i]];
        if(a[i+1] - a[i] == 1)
            sum += c[a[i]];
    }
    sum += b[a[n-1]];
    
    cout << sum << endl;
    
    
    return 0;
}




Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL<<60;

int LIS(const vector<long long> &a){
    int N = (int)a.size();
    vector<long long> dp(N, INF);
    for(int i = 0; i < N; i++){
        //dp[k] >= a[i]　となる最小のイテレータを見つける
        auto it = lower_bound(dp.begin(), dp.end(), a[i]);
        
        //そこをa[i]で置き換える
        *it = a[i];
    }

    //dp[k] < INF　となる最大のkに対してk+1が答え
    //それはdp[k] >= INFとなる最小のkに一致する
    return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}

int main(){
    int N; cin >> N;
    vector<long long> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    cout << LIS(a) << endl;
}


Measured memory_bytes: 4416
/****************************************

	LostMartian

****************************************/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for(ll i=m; i<n; i++)
#define repr(i,m,n) for(ll i=m; i>=n; i--)
#define vll vector<ll >
#define vvl vector<vector<ll > >
#define pi pair<ll, ll >
#define pb push_back
#define mk make_pair
#define sz size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define d(x) cout<<"Value of "#x" = "<<x<<"\n";
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define LOCAL #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
	clock_t z = clock();
	FAST
	//LOCAL
	ll n, k;
	cin>>n>>k;
	ll a[n];
	rep(i, 0, n) {
		cin>>a[i];
	}
	sort(a, a+n);
	ll sum=0;
	rep(i,0, k) {
		sum+=a[i];
	}
	cout<<sum<<"\n";

	debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 3800
#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()
using ll = long long;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;

string s, t;
int main(){
    cin >> s >> t;
    int s_len = s.size(), t_len = t.size();
    int pre[s_len - t_len + 1];
    memset(pre, 0, sizeof(pre));

    rep(i, s_len - t_len + 1){
        int temp = 0;
        rep(j, t_len){
            if(s[i + j] == t[j]) temp++;
        }
        pre[i] = t_len - temp;
    }

    int res = inf;
    for(auto a: pre) res = min(res, a);
    cout << res << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <utility>
using namespace std;
using ll = long long int;

int main() {
	
	ll N, P,tmp,ans;
	cin >> N >> P;
	ans = 1;

	if (N == 1) {
		cout << P;
		return 0;
	}


	for (ll i = 2; i <= 1e6; i++) {
		bool flag = true;
		tmp = P;
		for (int j = 0; j < N; j++) {
			if (tmp%i == 0) {
				tmp /= i;
			}
			else {
				tmp /= i;
				flag = false;
				break;
			}
		}
		if (flag)ans = i;
		if (tmp < 1)break;
	}
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	float N,limit,sum = 0;
  cin >> N >> limit;
  vector<float> a(N);
  froop1(0,N){
cin >> a.at(i);
    sum += a.at(i);
  }
  int count = 0;
  froop1(0,N){
    if(a.at(i) >= sum / (4 * limit)){
      count++;
    }
  }
  if(count >= limit){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3740
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int n;
   cin >> n;
   vector<string> w(n);

   rep(i,n) cin >>  w[i];

   bool flg = 1;
   rep(i,n){
      for(int j=i+1;j<n;j++){
         if(w[i] == w[j]) flg = 0;
      }
   }

   rep(i,n-1){
      if(w[i].back() != w[i+1].front()) flg = 0; 
   }

   if(!flg) cout << "No" << endl;
   else cout << "Yes" << endl;


   return 0;
}

Measured memory_bytes: 256
<?php
$n = trim(fgets(STDIN));
$n = explode(" ", $n);

if($n[0] < $n[1])
    $ope = " < ";
elseif($n[0] > $n[1])
    $ope = " > ";
elseif($n[0] == $n[1])
    $ope = " == ";

echo 'a' ,$ope, "b\n";

Measured memory_bytes: 6540
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
A_accsum = [0] * (N+1)
for i, a in enumerate(A):
    A_accsum[i+1] = (A_accsum[i]+a) % K

count = defaultdict(lambda: 0)
piv = A_accsum[0]
count[piv] += 1
ans = 0
for i in range(1, min(K, N+1)):
    a = A_accsum[i]
    count[a] += 1
for i in range(K, N + 1):
    a = A_accsum[i]
    piv = A_accsum[i-K]
    count[piv] -= 1
    ans += count[piv]
    count[a] += 1
for i in range(max(0, N - K+1), N+1):
    piv = A_accsum[i]
    count[piv] -= 1
    ans += count[piv]
print(ans)


Measured memory_bytes: 133300
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,ans = 0,a;
    cin >> n;
    rep(i,n){
        cin >> a;
        while(a%2 == 0){
            ans++;
            a /= 2;
        }
    }
    PRINT(ans);
}


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

void insort(int n, int a[])
{
        int max;
        for(int i = 0; i < n - 1; i++) {
                max = i;
                for(int j = i; j < n; j++)
                        if(a[j] > a[max])
                                max = j;
                swap(a[i], a[max]);
        }
}

int main(){
    int N,K;
    int l[50];
    cin >> N >> K;
    for(int i=0; i < N;i++){
         cin >> l[i];
    }
    insort(N,l);
        int ans = 0;
        for(int i = 0; i<K;i++){
                ans = ans + l[i];
        }
        cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    set<string> s;
    for(int i = 0;i<n;i++)
    {
        string str;
        cin>>str;
        s.insert(str);
    }
    cout<<s.size()<<endl;
}

Measured memory_bytes: 19056
#include <bits/stdc++.h>
#define maxn 200005
#define ll long long
#define ld double
#define mod 1000000007
using namespace std;
ll dp[maxn]; 
ll sum[maxn];
int n;
int c[maxn];
int main()
{
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>c[i];
	dp[n + 1] = 1;
	for(int i = n; i >= 1; i--)
	{
		dp[i] = dp[i + 1];
		if(c[i] != c[i + 1])
			dp[i] = (dp[i] + sum[c[i]]) % mod, sum[c[i]] += dp[i + 1], sum[c[i]] %= mod;
	//	cout<<i<<" "<<dp[i]<<endl;
	}
	cout<<dp[1]<<endl;
	return 0;
}
/*
20
10 
1 1
13 13
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10

*/

Measured memory_bytes: 4096
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int a= sc.nextInt();
        int b= sc.nextInt();
        int c= sc.nextInt();
        
        int x;
        int y=0;
        int count=0;
  
   for ( x = a; x <= b; x++) {
         y =c % x;
         if(y ==0){
         count++;

         }

   }
    System.out.println(count);
    }
}



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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const int N = 1e5 + 1;
vii adj[N];
int vet[N], edge[N];

void dfs(int u, int p) {
	int c = 1;
	for (auto x : adj[u]) {
		int v = x.first, i = x.second;
		if (v == p) continue;
		if (c == vet[u]) ++c;
		edge[i] = c;
		vet[v] = c++;
		dfs(v, u);
	}
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n; scanf("%d", &n);
	for (int i = 0; i < n-1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		adj[a].emplace_back(b, i);
		adj[b].emplace_back(a, i);
	}

	int root = 1;
	for (int i = 1; i <= n; i++) {
		if (adj[i].size() > adj[root].size()) root = i;
	}

	dfs(root, 0);
	printf("%lu\n", adj[root].size());
	for (int i = 0; i < n-1; i++)
		printf("%d\n", edge[i]);
}


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

int main()
{
  int N;
  cin >> N;
  vector<long long int> a(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a[i];
  }
  long long int ans = 0;
  for (int i = 0; i < N; i++)
  {
    while (a[i] % 2 == 0)
    {
      a[i] /= 2;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

ll a,b;
bool okasii = false;
int main() {
	cin >> a >> b;
	cout << a + b / 2 << endl;
}
	


Measured memory_bytes: 256
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(ll i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int x; cin >> x;
  if (x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
using namespace std;

int main(){
	string s;
	cin >> s;
	int max = 0;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
			int count = 1;
			for(;;){
				i++;
				if(!(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'))break;
				count++;
			}
			if(count > max)max = count;
		}
	}
	cout << max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define V vector
#define VI vector<int>
#define VL vector<ll>
#define VP vector<pair<int,int> >
#define VPL vector<pair<ll,ll> >
#define F first
#define S second
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

int main(){
    ins(n);ins(k);
    VI h(n);rep(i,n)in(h.at(i));
    sortall(h);
    int ans=INF;
    rep(i,n-k+1)ans=min(ans,h.at(i+k-1)-h.at(i));
    print(ans);
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

//Rectangular Searching
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int h = sc.nextInt();
			int w = sc.nextInt();
			if((h|w)==0)break;
			char[][] m = new char[h][w];
			for(int i=0;i<h;i++)m[i]=sc.next().toCharArray();
			int[][] c = new int[h][w];
			for(int i=0;i<h;i++){
				int x = 1;
				for(int j=w-1;j>=0;j--){
					if(m[i][j]=='.'){
						c[i][j] = x++;
					}
					else{
						c[i][j] = 0;
						x = 1;
					}
				}
			}
			int max = 0;
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					if(0<i&&c[i][j]==c[i-1][j]||c[i][j]==0)continue;
					int k = 1;
					int min = c[i][j];
					max = Math.max(max, k*min);
					while(i+k<h&&c[i+k][j]>0){
						min = Math.min(min, c[i+k][j]);
						k++;
						max = Math.max(max, k*min);
					}
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
long long  n,a[20];
int main(){
	cin>>n;
	int cnt=0;
	while(n)
	{
		a[++cnt]=n%10;
		n/=10;
	}
	int ans=0;
	ans+=(cnt-1)*9+a[cnt]-1;
	int sum=0;
	for(int i=1;i<=cnt;i++)
	{
		sum+=a[i];
	}
	cout<<max(sum,ans);
	return 0;
}

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

long long n, a, b, c, d;

int main()
{
	cin >> n >> a >> b >> c >> d;
	for (int i = 0; i <= n-1; i++) {
		long long ax = c*i, ay = d*i;
		long long bx = c*(n-1-i)+b-a, by = d*(n-1-i)+b-a;
	        if (ay < bx || by < ax) continue;
		else {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define maxn 100005
using namespace std;
int n,ans,f[maxn][30];
struct node { int v; node *nxt; } edge[maxn*2],*head[maxn],*ncnt;
void addedge(int u,int v)
{
	ncnt++;
	ncnt->v=v,ncnt->nxt=head[u];
	head[u]=ncnt;
}
void dfs(int u,int fa)
{
	for(node *p=head[u];p;p=p->nxt)
	{
		int v=p->v;
		if(v==fa) continue;
		dfs(v,u); 
		for(int i=0;i<=20;i++) f[u][i]+=f[v][i];
	}
	int p=0;
	for(int i=20;i>=0;i--)
		if(f[u][i]>1) { p=i+1; break; }
	while(f[u][p]) p++;
	f[u][p]++;
	for(int i=0;i<p;i++) f[u][i]=0;
	ans=max(ans,p);
}
int main()
{
	ncnt=&edge[0];
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v); addedge(v,u);
	}
	dfs(1,0);
	printf("%d\n",ans);
}


Measured memory_bytes: 21504
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
set<ll> st;
ll enum_divisors(long long N) {
    ll a = 1;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) {
            if (st.count(i))
                a = 0;
            if (N / i != i) {
                if (st.count(N / i))
                    a = 0;
            }
        }
    }
    return a;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
map<ll,ll> mp;
vector<ll> a(n);
rep(i,n){
    cin >> a[i];
    st.insert(a[i]);
    mp[a[i]]++;
}
ll ans = 0;
if(mp[1] == 1){
    cout << 1 << endl;
}
if(mp[1] > 2){
    cout << 0 << endl;
}
if(mp[1] == 0) {
    for (auto v : st) {
        if (mp[v] > 1)
            continue;
        ans += enum_divisors(v);
    }
    cout << ans << endl;

}
}

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  long long ans = 4 * n * q;
  ans = min(ans, 2 * n * h);
  ans = min(ans, n * s);
  if (n % 2 == 0) {
    ans = min(ans, n / 2 * d);
  } else {
    ans = min(ans, n / 2 * d + min({4 * q, 2 * h, s}));
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int solve(long long int x)
{
    if(x<10) return 1;
    return 1+solve(x/10);
}
int main()
{
    long long int N;
    scanf("%lld", &N);
    int ans = solve(N); 
    for(long long int i=1; i*i<=N; ++i)
    {
        if(N%i==0) ans = solve(N/i);
    }
    printf("%d\n", ans);
}

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

int main(){
    int a;
    int b;
    cin >> a >> b;
    if(a>b){
        cout << "a > b" << endl;
    }else if(a<b){
        cout << "a < b" << endl;
    }else if(a==b){
        cout << "a == b" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3068
#include<stdio.h>
int main(){
  unsigned long int x,i,max=0,j;
  
  scanf("%ld",&x);
  i=x;
  if(x==2){
    max=2;
  }
  while(max==0){
    for(j=2;j<((i/2)+1);j++){ 
    if(i%j==0){
      i++;
      break;
    }
      else{
        if(j==(i/2)){
        max=i;
          
          
        }
         
      }
    }
      
  }

    printf("%ld",max);

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;  //このネームスペースを使う

int main(){
  int N ;

  cin >> N ;
  
  if(N==1){
    cout << "Hello World" << endl;
  }
  else{
    int p[1];
    cin >> p[0] >> p[1];
    cout << p[0] + p[1] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<int,int> a, const pair<int,int> b) {
    return a.second < b.second;
}

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
    int N;
    vector<int>A;
    int ori[200000] = {0};

    cin >>N;

    for(int i = 0;i<N;i++){
      int a;
      cin >>a;
      A.push_back(a);
      ori[i] = a;
    }

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


    for(int i = 0;i<N;i++){
      int del = ori[i];
      if(del != A[N-1]){
        cout <<A[N-1]<<endl;
      }else{
        cout<<A[N-2]<<endl;

      }
    }

    return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;

*/

Measured memory_bytes: 3316
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 505;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
int pic[maxn][maxn];
vector<pii> ans1,ans2;
vector<int> anss1,anss2,anss3,anss4;
void print(int x1,int y1,int x2,int y2)
{
    if(x1==x2)
    {
        for(int i=y1;i<y2;i++)
        {
            anss1.push_back(x1);
            anss2.push_back(i);
            anss3.push_back(x1);
            anss4.push_back(i+1);
        }
    }
    else
    {
        for(int i=x1;i<x2;i++)
        {
            anss1.push_back(i);
            anss2.push_back(y1);
            anss3.push_back(i+1);
            anss4.push_back(y1);
        }
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf("%d",&pic[i][j]);
            pic[i][j]%=2;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(pic[i][j]==1)
            {
                int flag=0;
                for(int k=j+1;k<=m;k++)
                {
                    if(pic[i][k]==1)
                    {
                        flag=1;
                        pic[i][j]=0;
                        pic[i][k]=0;
                        ans1.push_back(pii(i,j));
                        ans2.push_back(pii(i,k));
                        break;
                    }
                }
                if(flag==0)
                {
                    pic[i][j]=0;
                    pic[i][m]=1;
                    ans1.push_back(pii(i,j));
                    ans2.push_back(pii(i,m));
                    break;
                }
            }
        }
    }

    for(int i=1;i<=n;i++)
    {
        if(pic[i][m]==1)
        {
            int flag=0;
            for(int j=i+1;j<=n;j++)
            {
                if(pic[j][m]==1)
                {
                    flag=1;
                    pic[i][m]=0;
                    pic[j][m]=0;
                    ans1.push_back(pii(i,m));
                    ans2.push_back(pii(j,m));
                    break;
                }
            }
            if(flag==0) break;
        }
    }
    int sz=ans1.size();
    for(int i=0;i<sz;i++)
    {
        print(ans1[i].first,ans1[i].second,ans2[i].first,ans2[i].second);
    }
    sz=anss1.size();
    printf("%d\n",sz);
    for(int i=0;i<sz;i++)
    {
        printf("%d %d %d %d\n",anss1[i],anss2[i],anss3[i],anss4[i]);
    }
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 8044
#include<iostream>

using namespace std;

int main(){
	int n,bunri[6]={0};
	char hoshi='*';
	double length,hantei[5];
	
	for(int i=0;i<5;i++){
		hantei[i]=165+i*5;
	}
	
	cin>>n;
	for(int i=0;i<n;i++){
		
		cin>>length;
		if(length<hantei[0]){
			bunri[0]++;
		}
		else if(length>hantei[4]){
			bunri[5]++;
		}
		else{
			for(int j=1;j<5;j++){
				if((hantei[j-1])<=length && length<hantei[j]){
					bunri[j]++;
					break;
				}
			}
		}
	}
	
	for(int i=0;i<6;i++){
		cout<<1+i<<":";
		for(int j=0;j<bunri[i];j++){
			cout<<hoshi;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1232
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	cin>>n;
	int num;
	int fish;
	int ansnum;
	int ansfish=-1;
	rep(i,n){
		cin>>num>>fish;
		if(ansfish<fish){
			ansfish=fish;
			ansnum=num;
		}else if(ansfish==fish){
			if(ansnum>num){
				ansfish=fish;
				ansnum=num;
			}
		}
	}
	cout<<ansnum<<" "<<ansfish<<endl;
	return 0;
}

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

template <typename T>
using Matrix = vector<vector<T>>;

template <typename T>
Matrix<T> matrix(const int R, const int C, const T x = T()) { return Matrix<T>(R, vector<T>(C, x)); }

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

    string s; cin >> s;
    const auto n = int(s.size());

    auto f = matrix<int>(n+2, 27, n+1);
    for (auto i = n-1; i >= 0; i--)
    {
        const auto start = s[i]-'a';
        f[i][start] = i+1;
        for (auto c = start+1; c <= 26; c++)
            f[i][c] = f[f[i][c-1]][c-1];
        for (auto c = 0; c < start; c++)
            f[i][c] = f[f[i][26]][c];
    }

    const auto log = 18;
    auto jumps = matrix<int>(log+1, n+2);
    for (auto i = 0; i < n+2; i++)
        jumps[0][i] = f[i][26];
    for (auto k = 1; k <= log; k++)
        for (auto i = 0; i < n+2; i++)
            jumps[k][i] = jumps[k-1][jumps[k-1][i]];

    int Q; cin >> Q;
    for (auto q = 0; q < Q; q++)
    {
        int l, r; cin >> l >> r;
        l--; r--;

        auto x = l;
        for (auto k = log; k >= 0; k--)
            if (jumps[k][x] <= r+1) x = jumps[k][x];
        cout << (x == r+1 ? "Yes" : "No") << "\n";
    }
}


Measured memory_bytes: 114076
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };


int main(void) {

	vector<int>a(3);

	FOR(i, 0, 2) {
		cin >> a[i];
	}

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

	cout << a[2] - a[0] << endl;



	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s;
	cin>>s;
	deque<char> ans;
	rep(i,n){
		ans.push_back(s[i]);
	}
	int now=0;
	rep(i,n){
		if(s[i]=='(') now++;
		else now--;
		if(now<0){
			ans.push_front('(');
			now++;
		}
	}
	rep(i,now){
		ans.push_back(')');
	}
	rep(i,ans.size()){
		cout<<ans[i];
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <stdio.h>
#include <map>
#define MAXN 200005
using namespace std;
map<int,int> m;
int sum[MAXN];
int main(){
	int n,t;
	scanf("%d",&n);
	for(int i=1; i<=n;i++){
		scanf("%d",&sum[i]);
		m[i] = sum[i];
	}
	sort(sum+1,sum+1+n);
	for(int i=1;i<=n;i++){
		if(m[i]<=sum[n/2]) printf("%d\n",sum[n/2+1]);
		else printf("%d\n",sum[n/2]);
	}
	return 0;
} 

Measured memory_bytes: 12288