akhauriyash/Code-Regression huggingface dataset:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.*;
/**
 *
 * @author arvin
 */
public class Main {
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        sc.nextLine();
        int a[]=new int[n];
        long dp[]=new long[n+5];
        String abc[]=sc.nextLine().split(" ");
        for(int i=0;i<n;i++)
           a[i]=Integer.parseInt(abc[i]);
        
        dp[n-1]=0;
        for(int i=n-2;i>=0;i--)
        {
            long x=Long.MAX_VALUE;
            for(int j=1;j<=k && i+j<n;j++)
                x=Math.min(dp[i+j]+Math.abs(a[i]-a[i+j]),x);
            dp[i]=x;
        }
        System.out.println(dp[0]);
    }
}


Measured memory_bytes: 48804
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        if (n == 2) {
            System.out.println(max(a[0], a[1]));
            return;
        }
        if (n == 3) {
            System.out.println(max(a[0], a[1], a[2]));
            return;
        }
        if (n % 2 == 0) {
            long[] dp = new long[n];
            dp[0] = a[0];
            dp[1] = a[1];
            for (int i = 2; i < n; i++) {
                if (i % 2 == 0) {
                    dp[i] = a[i] + dp[i - 2];
                } else {
                    dp[i] = a[i] + max(dp[i-2],dp[i-3]);
                }
            }
            System.out.println(max(dp[n-1],dp[n-2]));
        } else {
            long[][] dp = new long[3][n];
            for (int i = 0; i < 3; i++) {
                Arrays.fill(dp[i], Long.MIN_VALUE);
            }
            dp[0][0] = a[0];
            dp[1][1] = a[1];
            dp[0][2] = a[0]+a[2];
            dp[2][2] = a[2];
            for (int i = 3; i < n; i++) {
                if(i%2==0){
                    dp[0][i] = a[i] + dp[0][i-2];
                    dp[2][i] = a[i] + max(dp[2][i-2], dp[1][i-3], dp[0][i-4]);
                }else{
                    dp[1][i] = a[i] + max(dp[1][i-2], dp[0][i-3]);
                }
            }
            System.out.println(max(dp[2][n-1],dp[1][n-2],dp[0][n-3]));
        }
    }

    private static int max(int... a) {
        int max = a[0];
        for (int i : a) {
            if (i > max) max = i;
        }
        return max;
    }

    private static long max(long... a) {
        long max = a[0];
        for (long i : a) {
            if (i > max) max = i;
        }
        return max;
    }
}

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

int main()
{
	int a,b;
	bool flag = false;
	cin >> a >> b;

	for (int i = 1; i <= 3; ++i)
	{
		if (a*b*i%2) {
			flag = true;
			break;
		}
	}

	if (flag) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    priority_queue<P> q;
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        q.push(P(b[i], i));
    }
    ll ans = 0;
    while (!q.empty()) {
        int id = q.top().second;
        q.pop();
        ll bc = b[(id - 1 + n) % n] + b[(id + 1) % n];
        if (a[id] == b[id]) {
            continue;
        }
        if (a[id] >= bc) {
            if ((b[id] - a[id]) % bc == 0) {
                ans += (b[id] - a[id]) / bc;
                b[id] = a[id];
            } else {
                cout << -1 << endl;
                return 0;
            }
        } else {
            ans += b[id] / bc;
            if (b[id] < bc) {
                cout << -1 << endl;
                return 0;
            }
            b[id] %= bc;
            if (b[id] < a[id]) {
                cout << -1 << endl;
                return 0;
            } else if (b[id] > a[id]) {
                q.push(P(b[id], id));
            }
        }
    }
    cout << ans << endl;
}


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

int main()
{
  int n; cin >> n;
  vector<int> a(n+1);
  vector<int> b(n);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll ans = 0;
  rep(i, n) {
    ans += min(a[i], b[i]);
    int t = max(0, b[i]-a[i]);
    ans += min(a[i+1], t);
    a[i+1] = max(0, a[i+1]-t);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

int main(){
   int N, M, A;
   std::cin >> N >> M;

   int sum = 0;
   for(int i=0; i<M; ++i) {
      std::cin >> A;
      sum += A;
   }
   std::cout << (sum <= N ? N - sum : -1) << std::endl;
   return 0;

}


Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 200005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	string a,b;
	cin>>a>>b;
	ll k,l;
	cin>>k>>l;
	string s;
	cin>>s;
	if(s==a) k--;
	else if(s==b) l--;
	cout<<k<<" "<<l;

	return 0;
}

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

int main()
{
	string a,b,c;
	cin>>a>>b>>c;
	
	cout<<(char)(a.front()+'A'-'a')<<(char)(b.front()+'A'-'a')<<(char)(c.front()+'A'-'a')<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    string s;cin>>s;
    ll ans=0;
    rep(i,s.size()){
        if(s.at(i)=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
def read_ints():
    return map(int, input().split(' '))


mod = int(1e9 + 7)


def fexp(x, y):
    ret = 1
    while y > 0:
        if y % 2 == 1:
            ret = ret * x % mod
        x = x * x % mod
        y = y // 2
    return ret


input()
a = list(read_ints())
s = sum(a)
ans = 0
for i in a:
    ans = (ans + i * (s - i)) % mod
print(ans * fexp(2, mod - 2) % mod)


Measured memory_bytes: 31428
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
using namespace std;
using ll = long long;

/*int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >> P[i];
    P[i]--;
  }
  int ans=0;
  for(int i=0;i<N;i++){
    if(i==0){
      if(i==P[i]){
        swap(P[i],P[i+1]);
        ans++;
      }
    }
    else if(i==N-1){
      if(i==P[i]){
        swap(P[i],P[i-1]);
        ans++;
      }
    }
    else{
      if(i==P[i]){
        if(P[i-1]!=i-1){
          swap(P[i-1],P[i]);
          ans++;
        }
        else{
          swap(P[i],P[i+1]);
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}
*/

int main(){
  int N;
  cin >> N;
  int count=0;
  int ans=0;
  for(int i=0;i<N;i++){
    int p;
    cin >> p;
    p--;
    if(i==p){
      count++;
    }
    else{
      ans+=(count+1)/2;
      count=0;
    }
  }
  if(count!=0){
    ans+=(count+1)/2;
  }
  cout << ans << endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n,m,Q;cin >>n>>m>>Q;
    vector<vector<ll>> a(n,vector<ll>(n,0));
    for (int i = 0; i <m ; ++i) {
        ll l ,r;cin >>l>>r;
        l--;r--;
        a[l][r]++;
    }
    vector<vector<ll>>s(n+1,vector<ll>(n+1,0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            s[i+1][j+1]=s[i][j+1]+s[i+1][j]-s[i][j]+a[i][j];
        }
    }
    for (int i = 0; i <Q ; ++i) {
        ll p,q;cin >>p>>q;
        p--;
        cout <<s[q][q]-s[p][q]-s[q][p]+s[p][p]<<endl;
    }
    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

  int N, K, C;
  cin >> N >> K >> C;
  string s;
  cin >> s;

  int cnt = 0;
  int idx = 0;
  vi front;
  while (idx < s.size() && cnt <= K) {
    if (s[idx] == 'o') {
      front.pb(idx);
      idx += C+1;
      cnt++;
    } else {
      idx++;
    }
  }
  cnt = 0;
  idx = s.size() - 1;
  vi back;
  while (idx >= 0 && cnt <= K) {
    if (s[idx] == 'o') {
      back.pb(idx);
      idx -= C+1;
      cnt++;
    } else {
      idx--;
    }
  }
  reverse(All(back));
  vi ans;
  rep(i, 0, K) {
    if (front[i] == back[i]) {
      ans.pb(front[i]);
    }
  }

  sort(All(ans));
  for (int a: ans) {
    cout << a+1 << endl;
  }

  return 0;
};


Measured memory_bytes: 4236
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <math.h>
#include <vector>
 
#define MOD 1000000007
typedef long long ll;
 
using namespace std;


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

	ll t, n, ans = 0;

	cin >> n;
	
	if(n>=30) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2);
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"

//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;

  rep(i,s.size()){
    if(s[i]!=s[s.size()-i-1]){
      prt("No"); return 0;
    }
  }

  rep(i,(s.size()-1)/2-1){
    if(s[i]!=s[(s.size()-1)/2-1-i]){
      prt("No"); return 0;
    }
  }

  REP(i,(s.size()+3)/2-1,s.size()-1){
    if(s[i]!=s[s.size()-1-i]){
      prt("No"); return 0;
    }
  }

  prt("Yes");


}


Measured memory_bytes: 256
//unsolved

#include<bits/stdc++.h>
using namespace std;

//#define DEBUG 1
#define REP(i,n) for(int i=0;i<n;i++)
int m,n;
int p[20002];
int s[20002];
int c,e;
int dp[20002][502];

int main(){
  cin>>m>>n;
  REP(i,m)cin>>p[i];
  sort(p,p+m,greater<int>());
  REP(i,20001)s[i+1]=s[i]+p[i];
  int ma=0;
  REP(j,n){
    cin>>c>>e;
    REP(i,m+1){
      int a,b,d;
      a=dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
      b=dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
      d=dp[i+c][j+1]=max(dp[i+c][j+1],dp[i][j]+s[i+c-1]-s[i-1]-e);
      ma=max(max(max(ma,a),b),d);
    }
  }
  #ifdef DEBUG
  REP(i,n+1)cout<<p[i]<<" ";
  cout<<endl;
  REP(i,m+1){
    REP(j,n+1)cout<<dp[j][i]<<" ";
    cout<<endl;
  }
  #endif
  cout<<ma<<endl;
  return 0;
}

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

int N;
int Y;

void input() {
    cin >> N;
    cin >> Y;
}

int main() {
    input();
    int n1000 = 0;
    int n5000 = 0;
    int n10000 = 0;
    int diff = 0;

    // 一番少ない枚数で算出
    n10000 = Y / 10000;
    n5000 = (Y - n10000 * 10000) / 5000;
    n1000 = (Y - n10000 * 10000 - n5000 * 5000) / 1000;
    
    if((n10000 + n5000 + n1000) == N){
        // 何もしない
    } else if ((n10000 + n5000 + n1000) > N){
        n10000 = -1;
        n5000 = -1;
        n1000 = -1;
    } else{
        diff = N - (n10000 + n5000 + n1000);

        while(diff){
            // 最優先 5000 -> 1000 * 5
            if (n5000 > 0 && diff >= 4){
                n5000--;
                n1000 += 5;
            } else if (n10000 > 0 && diff >= 1){
                n10000--;
                n5000 += 2;
            } else{
                n10000 = -1;
                n5000 = -1;
                n1000 = -1;
                break;
            }
            diff = N - (n10000 + n5000 + n1000);
        }
    }

    cout << n10000 << " " << n5000 << " " << n1000 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> A = new ArrayList<Integer>();

        for (;;) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                for (int i=0; i<A.size(); i=i+2) {
                    for (int j=0; j<A.get(i); j++) {
                        for (int k=0; k<A.get(i+1); k++) {
                            if ((j + k) % 2 == 0) {
                                System.out.print("#");
                            }
                            else {
                                System.out.print(".");
                            }
                        }
                        System.out.println();
                    }
                    System.out.println();
                }
                break;
            }
            else {
                A.add(H);
                A.add(W);
            }
        }

    }
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
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);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}


bool check(string s){
    for(auto c : s){
        if(c != s[0]) return false;
    }
    return true;
}


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string alp(26, 'a');
    iota(alp.begin(), alp.end(), 'a');
    string s;
    cin >> s;
    int ans = 1e9;
    if(check(s)) {
        ppp(0);
        return 0;
    }
    for(int i = 0; i < 26; ++i){
        string t = s;
        int cnt = 0;
        while(1){
            cnt++;
            string tmp = "";
            for(int j = 0; j < t.size()-1; ++j){
                if(t[j] == alp[i] or t[j+1] == alp[i])
                    tmp += alp[i];
                else
                    tmp += t[j];
            }
            if(check(tmp)){
                ans = min(ans, cnt);
                break;
            }
            t = tmp;
        }

    }
    ppp(ans);




    return 0;
}


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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    int n = c - a - b; 
    if(n >= 0 && (4 * a * b < (c - a - b) * (c - a - b)))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int a[3];

int main(){
    INIT;
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << a[2]*10 + a[1] + a[0] << endl;
}

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

int main(){
  int k, s, answer = 0;

  cin >> k >> s;

  for(int x = 0; x < k + 1; x++){
    for(int y = 0; y < k + 1; y++){
      if(s <= x + y + k && s >= x + y){
        answer++;
      }
    }
  }

  cout << answer << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

int main(){
    int n;scanf("%d",&n);
    int ans=1,cnt,max=-1,x;
    for(int i=2;i<=n;i++){
        x=i;
        cnt=0;
        while(1){
            cnt++;
            x/=2;
            if(x%2||x==0)break;
        }
        if(max<cnt){
            max=cnt;
            ans=i;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
 
using namespace std;
typedef long long LL;
const int N = 600050;
 
int head[N], to[N], nex[N], tot = 1, vis[N], ans[N], oe[N], oe2[N], n;
void addedge(int u, int v){
	tot ++; to[tot] = v, nex[tot] = head[u], head[u] = tot;
	tot ++; to[tot] = u, nex[tot] = head[v], head[v] = tot;
}
void dfs(int x){
	for(int i = head[x]; i; i = head[x]){
		head[x] = nex[i];
		if(vis[i] == 0){
			vis[i] = 1;
			vis[i ^ 1] = 1;
			if(to[i] == x + n)
				ans[x] = 1;
			else if(to[i] == x - n)
				ans[x - n] = -1;
			dfs(to[i]);
		}
	}
}
	
int main()
{
 
	int i, j, k, ra, rb;
	scanf("%d", &n);
	for(i = 1; i <= n; i ++){
		scanf("%d", &j), oe[j] ^= 1;
		if(j != -1)addedge(i, j);
		else ra = i;
	}
	for(i = 1; i <= n; i ++){
		scanf("%d", &k), oe2[k] ^= 1;
		if(k != -1)addedge(i + n, k + n);
		else rb = i + n;
	}
	for(i = 1; i <= n; i ++){
		if(oe2[i] != oe[i]){
			puts("IMPOSSIBLE");
			return 0;
		}else if(oe[i] == 0)
			addedge(i, i + n); 
	}
	addedge(ra, 2 * n + 1);
	addedge(rb, 2 * n + 1);
	puts("POSSIBLE"), dfs(1);
	for(i = 1; i <= n; i ++)
		printf("%d ", ans[i]);
 
	return 0;
}

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

using ll = long long;
#define REPR(i, n) for( int i = n; i >= 0; --i )
#define REP(i, n) for( int i = 0; i < (int)(n); ++i )
#define FOR(i, m, n) for( int i = m; i < (int)(n); ++i )
#define ALL(v) v.begin(), v.end()


int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    REP(i, N) cin >> V[i];


    // 取り出す右点と左点で全探索
    ll ans = 0;
    REP(l,N+1){
        FOR(r,l,N+1){
            if( l+(N-r) > K ) continue;
            vector<int> tmp;
            ll tmp_sum = 0;
            REP(i, l){ tmp.push_back(V[i]); tmp_sum += V[i]; }
            FOR(i, r, N){ tmp.push_back(V[i]); tmp_sum += V[i]; }
            sort(ALL(tmp));
            int can_minus = K-(l+(N-r)), idx = 0;
            while( idx < tmp.size() and can_minus > 0 and tmp[idx] < 0 ){
                tmp_sum -= tmp[idx];
                ++idx, --can_minus;
            }
            //cout << l << " " << r << " " << tmp_sum << endl;
            ans = max(ans, tmp_sum);
        }
    }
    cout << ans << endl;

    return 0;
}

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

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

    int ans = 1;
    for (int b = 2; b * b <= x; b++) {
        int tmp = b * b;
        while (tmp * b <= x) {
            tmp = tmp * b;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
As = list(map(int, input().split()))
adic = {}
for a in As:
    adic[a] = adic.get(a, 0) + 1

Ds = []
for a in adic:
    Ds.append([a, adic[a]])
for i in range(M):
    B, C = map(int, input().split())
    Ds.append([C,B])

Ds.sort(reverse=True)

count, sum = 0,0
for D in Ds:
    c = D[1] if D[1] + count <= N else N - count
    sum += c * D[0]
    count += c
    if count == N:
        break

print(sum)

Measured memory_bytes: 41000
# coding: utf-8
N = int(input())
A = {}
for i in range(N):
    a = int(input())
    l = []
    for j in range(a):
        tmp = list(map(int, input().split()))
        l.append(tmp[:])
    A[i+1] = l[:]
# print(A)

ans = -1
for bit in range(2**N):
    l = []
    # 正直者と嘘つきの配列
    for i in range(N):
        if (bit >> i) & 1 == 1:
            l.append(1)
        else:
            l.append(0)
    
    flag = True
    for i in range(N):
        if (bit >> i) & 1 == 1:
            for j in range(len(A[i+1])):
                if l[A[i+1][j][0]-1] != A[i+1][j][1]:
                    flag = False
    # print(*l)
    # print(flag)
    if flag:
        ans = max(ans, sum(l))
    # if len(l) <= 2:
    #     ans = 1
print(ans)

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

int A[10000]={};


void sort(int N){
  for(int i=1;i<N;i++){
    for(int t=i;t>0;t--){
      if(A[t]<A[t-1]){swap(A[t],A[t-1]);}
      else{break;}
    }
    
  for(int t=0;t<N;t++){
    cout<<A[t];
    if(t!=N-1){cout<<" ";}
    else{cout<<endl;}
    }
  }}

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

for(int t=0;t<n;t++){
    cout<<A[t];
    if(t!=n-1){cout<<" ";}
    else{cout<<endl;}
    }

 sort(n);
  
  
  return 0;
}



Measured memory_bytes: 3080
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A = [ir() for _ in range(5)]
K = ir()
length = A[-1] - A[0]
bl = length <= K
print('Yay!' if bl else ':(')


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main(void){
  char S[100001];
  int i;
  int ans=0;
  scanf("%s",S);
  for(i=0;i<strlen(S)-1;i++){
    if(S[i] == 'W' && S[i+1] == 'B'){
      ans++;
    }else if(S[i] == 'B'&& S[i+1] == 'W'){
      ans++;
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<set>
#include<ctime>
using namespace std;

#define rep(i,m) for(int i=0;i<m;i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define mm1(x) memset(x,-1,sizeof(x))
#define ms(x,n) memset(x,n,sizeof(x))
#define SORT(x) sort((x).begin(),(x).end())
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

const int INF = 100000000;
const int mod = 1e9 + 7;


int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a%b);

}

int main() {
	int a, b; cin >> a >> b;
	cout << abs(a - b) << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, r, l;
  cin >> n >> r >> l;
  priority_queue<pair<lol, lol> > ans;
  lol Score[n + 5] = {}; //点数を保持
  lol Time[n + 5] = {}; //映った時間を保持
  //初期化
  reps(i, n){
    ans.emplace(Score[i], -i);
  }
  int d, t, x, memo = 0;
  rep(i, r){
    cin >> d >> t >> x;
    while(ans.top().first != Score[-ans.top().second]){
      ans.pop();
    }
    Time[-ans.top().second] += (t - memo);
    memo = t;
    Score[d] += x;
    ans.emplace(Score[d], -d);
  }
  while(ans.top().first != Score[-ans.top().second]){
    ans.pop();
  }
  Time[-ans.top().second] += (l - t);
  //最大値を求める
  int ansp = 0;
  reps(i, n){
    if(Time[ansp] < Time[i]){
      ansp = i;
    }
  }
  cout << ansp << '\n';
  return 0;
}



Measured memory_bytes: 20904
from itertools import accumulate
N,C = map(int,input().split())
xs = []
vs = []
for _ in range(N):
    x,v = map(int,input().split())
    xs.append(x)
    vs.append(v)
vacc = [0]+list(accumulate(vs, lambda x,y:x+y))
lacc = [0]+[vacc[i+1]-xs[i] for i in range(N)]
racc = [vacc[-1]-vacc[i]-C+xs[i] for i in range(N)]+[0]
for i in range(1, N):
    lacc[i] = max(lacc[i], lacc[i-1])
racc[-1] = (racc[-1], 0)
for i in range(N, 0, -1):
    if racc[i-1] > racc[i][0]:
        racc[i-1] = (racc[i-1], C-xs[i-1])
    else:
        racc[i-1] = racc[i]
xs = [0]+xs
ans = 0
for i in range(N+1):
    l = lacc[i]
    r, d = racc[i]
    ans = max(ans, l+r-xs[i], l+r-d, l, r)
print(ans)

Measured memory_bytes: 40200
using System;

namespace PrimeNumber
{
    class Program
    {
        private static bool?[] arr = new bool?[1000000];

        private static bool Save(int n, bool b)
        {
            arr[n] = b;
            return b;
        }

        private static bool IsPrime(int n)
        {
            if (arr[n] != null) return (bool)arr[n];
            if (n == 2) return Save(n, true);
            if (n % 2 == 0) return Save(n, false);

            double l = Math.Sqrt(n);

            for (var i = 3; i <= l; i += 2)
                if (n % i == 0) return Save(n, false);
       
            return Save(n, true);
        }

        static void Main(string[] args)
        {
            int num;
            
            while (int.TryParse(Console.ReadLine(), out num))
            {
                var count = num >= 2 ? 1 : 0;
                for (var i = 3; i <= num; i+=2)
                    if (IsPrime(i)) count++;
                Console.WriteLine(count);
            }
        }
    }
}


Measured memory_bytes: 11120
n=int(input())
a=list(map(int,input().split()))

import fractions as math

l=[0]
r=[0]
for i in range(n-1):
  li=math.gcd(l[i],a[i])
  l.append(li)
  ri=math.gcd(r[i],a[n-i-1])
  r.append(ri)
m=[]
for i in range(n):
  mi=math.gcd(l[i],r[n-i-1])
  m.append(mi)

print(max(m))

Measured memory_bytes: 14052
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]

# base_score[i] := i の立っている bit のウサギで一つのグループを作るときの特典
base_score = [0]*(1<<N)
for i in range(1<<N):
    for j in range(N):
        for k in range(j):
            if i & (1<<j) and i & (1<<k):
                base_score[i] += a[j][k]

# dp[i] := i の立っている bit のウサギのグループが決まっているとした場合の得点の最大値
dp = [0]*(1<<N)
for i in range(1<<N):
    # i の部分集合について、ウサギのグループの分け方を全探索
    j = i
    while j > 0:
        dp[i] = max(dp[i], dp[i-j]+base_score[j])
        j = (j-1)&i

print(dp[(1<<N)-1])

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

int par[10000], high[10000];
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y)return;
	if (high[x] > high[y])par[y] = x;
	else {
		par[x] = y;
		if (high[x] == high[y])high[y]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int main() {
	int n, q; scanf("%d%d", &n, &q);
	rep(i, n)par[i] = i;
	rep(i, q) {
		int com, x, y; scanf("%d%d%d", &com, &x, &y);
		if (com)printf("%d\n", same(x, y));
		else unite(x, y);
	}
}

Measured memory_bytes: 3292
/*
 * @Autor: valk
 * @Date: 2020-04-04 14:56:12
 * @LastEditTime: 2020-09-17 16:41:17
 * @Description: 如果邪恶  是华丽残酷的乐章 它的终场 我会亲手写上 晨曦的光 风干最后一行忧伤 黑色的墨 染上安详
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define emplace_back push_back
#define pb push_back
// #define fuck(a, b) cout << a << ' ' << b << ' ' << endl
// #define fuck(a, b, c) cout << a << ' ' << b << ' ' << c << ' ' << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int seed = 12289;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

int main()
{
    int x;
    scanf("%d", &x);
    if(x==1){
        printf("0\n");
    }else{
        printf("1\n");
    }
    return 0;
}

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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int x,n,t;
    cin >> x >> n;
    set<int> p;
    rep(i,n){
        cin >> t;
        p.emplace(t);
    }
    int ans=200;
    rep(i,110){
        if(p.count(i)) continue;
        if(abs(x-i)<abs(x-ans)) ans = i;
        if(i-x > ans) break;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<ll>());
    ll b[N + 1]{};
    for (int i = 0; i < N; i++) {
        b[i + 1] = b[i] + A[i];
    }
    ll A_MAX = 2 * 100000 + 1;
    ll d[A_MAX]{}; // d[i]: パワーi以上を持つ人の数
    for (int i = 0; i < N; i++) {
        d[A[i]]++;
    }
    for (int i = A_MAX - 1; i >= 1; i--) {
        d[i - 1] += d[i];
    }
    ll l = -1;
    ll r = A_MAX;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        ll s = 0;
        for (int i = 0; i < N; i++) {
            s += d[max(1ll, m - A[i])];
        }
        if (s >= M) {
            l = m;
        } else {
            r = m;
        }
    }
    
    ll ans = 0;
    ll s = 0; // 握手した人の合計 
    for (int i = 0; i < N; i++) {
        int v = max(0, (int)(r - A[i]));
        ll t = max(0ll, min(d[v], M - s));
        ans += b[t] + t * A[i];
        s += t;
    }
    ans += l * (M - s);
    
    cout << ans << "\n";
    
    return 0;
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int n, c; cin >> n >> c;
    int d[c][c];
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < c; j++) cin >> d[i][j];
    }
    int cnt[c][3];
    memset(cnt, 0x00, sizeof(cnt));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int cij; cin >> cij; cij--;
            cnt[cij][(i + j + 2) % 3]++;
        }
    }

    int ans = inf;
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < c; j++) {
            for (int k = 0; k < c; k++) {
                if (i == j || j == k || k == i) continue;
                int tmp = 0;
                for (int l = 0; l < c; l++) {
                    tmp += d[l][i] * cnt[l][0];
                    tmp += d[l][j] * cnt[l][1];
                    tmp += d[l][k] * cnt[l][2];
                }
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int n; bool used[22370000]; char com[7], s[13];
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%s %s", com, s);
		int h = 0, l = strlen(s);
		for(int j = 0; j < l; j++) {
			h *= 4;
			if(s[j] == 'A') h++;
			else if(s[j] == 'C') h += 2;
			else if(s[j] == 'G') h += 3;
		}
		h += (1 << (2 * l));
		if(com[0] == 'i') used[h] = true;
		else puts(used[h] ? "yes" : "no");
	}
}

Measured memory_bytes: 3916
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    int K;
    string S;
    cin >> K >> S;
    int n = (int)(S.length());
    if(n<=K) cout << S << endl;
    else{
        rep(i, K) cout << S[i];
        cout << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define INF 1001001001001001001
#define MAX_V 100000

struct edge{int to; long long cost;};
typedef pair<long long,int> P;

int V;
vector<edge> G[MAX_V];
long long d[MAX_V];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(edge e : G[v]) {
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> V;
    for(int i=0; i<V-1; ++i) {
        int u,v;
        long long w;
        cin >> u >> v >> w;
        --u; --v;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    dijkstra(0);

    for(int i=0; i<V; ++i) {
        if(d[i] % 2 == 0) cout << 0 << endl;
        else cout << 1 << endl;
    }
}

Measured memory_bytes: 8704
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  xus <- replicateM n getLine
  print $ solve xus

solve :: [String] -> Double
solve [] = 0.0
solve (xu:xus)
  | u == "JPY" = x + solve xus
  | u == "BTC" = x * 380000.0 + solve xus
  where
    x = read $ head $ words xu
    u = last $ words xu
  


Measured memory_bytes: 636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}
#

int main() {
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	int shiftx = x2 - x1, shifty = y2 - y1;
	cout << x2 - shifty << " " << y2 + shiftx << " " << x1 - shifty << " " << y1 + shiftx;


	cout << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end(),greater<ll>());
    ll happiness = 0;
    for(int i = 1; i < n; i++){
        happiness += a[i/2];
    }
    cout << happiness << endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> Qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> Qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(1) {
      c-=b;
      if(c<=0) {
        cout << "Yes" << endl;
        break;
      }
      a-=d;
      if(a<=0) {
        cout << "No" << endl;
        break;
      }
    }
  return 0;
}


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

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

    int N;
    cin >> N;
    string s;
    cin >> s;
    
    vector<char> v;
    v.push_back(s[0]);
    char now = s[0];
    rep(i,N){
        if(now == s[i]){
            continue;
        }else{
            now = s[i];
            v.push_back(s[i]);
        }
    }
    
    cout << v.size() << endl;

    return 0;
}

Measured memory_bytes: 592
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
int ans=0,mx=INT_MAX;
int n;
cin>>n;
forn(i,n)
{
  int x;
  cin>>x;
    mx=min(mx,x);
  if(mx>=x)ans++;

}
cout<<ans;




    return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int i = 0;
    if (n % 2 == 0) {
        while (s[n/2-1-i] == s[n/2+i] && s[n/2-1-i] == s[n/2-1]) i++;
        cout << n / 2 + i << endl;
        return 0;
    }
    while (s[n/2-i] == s[n/2+i] && s[n/2-i] == s[n/2]) i++;
    cout << n / 2 + i << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
class UnionFind {
public:
  vector <int> par; // 各元の親を表す配列
  vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
  // Constructor
  UnionFind(int sz_): par(sz_), siz(sz_, 1) {
    for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
  }
  void init(int sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1LL);
    for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
  }
 
  // Member Function
  // Find
  int root(int x) { // 根の検索
    while (par[x] != x) {
      x = par[x] = par[par[x]]; // x の親の親を x の親とする
    }
    return x;
  }
 
  // Union(Unite, Merge)
  bool merge(int x, int 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(int x, int y) { // 連結判定
    return root(x) == root(y);
  }
 
  ll size(int x) { // 素集合のサイズ
    return siz[root(x)];
  }
};
 
int main() {
  int n,m;
  cin >> n >> m;
  UnionFind uf(n);
  ll ans = ((ll)n*((ll)n-1LL))/2LL;
  vector<P> bs(m);
  rep(i,0,m) cin >> bs[i].fi >> bs[i].se;
  vector<ll> a(m);
  rrep(i,m,0) {
    a[i] = ans;
    int a = bs[i].fi, b = bs[i].se;
    a--; b--;
    if (!uf.issame(a, b)) {
      ll sa = uf.size(a), sb = uf.size(b);
      ans -= sa * sb;
      uf.merge(a, b);
    }
  }
  rep(i,0,m) cout << a[i] << "\n";
  return 0;
}

Measured memory_bytes: 5880