akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define int long long int
signed main() 
{
    FAST
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string x,y;
    cin>>x>>y;
    int a=x.size(),b=y.size();
    std::vector<std::vector<int> > dp;
    std::vector<int> row;
    fr(i,b+1) row.pb(0);
    fr(i,a+1) dp.pb(row);

    for(int i=1;i<a+1;i++)
    {
        for(int j=1;j<b+1;j++)
        {
            int ind=i-1,pos=j-1;
            if(x[ind]==y[pos])
            {
                dp[i][j]=max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1]));
            }
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }

    // fr(i,a+1)
    // {
    //     fr(j,b+1)
    //     cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }

    string str;
        int i=a,j=b;
        while(i>0 && j>0){
            if(dp[i][j]==dp[i][j-1]) j--;
            else if(dp[i][j]==dp[i-1][j]) i--;
            else str+=x[i-1],i--,j--;
            //p1(str);
        }
        reverse(str.begin(),str.end());
        cout<<str<<endl;

    return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;
int n,m;
vector<int> Adj[100010];
int dp[100010];

int Solve(int x)
{
    dp[x] = 1;

    for(int i=0;i<Adj[x].sz;i++)
    {
        int to = Adj[x][i];
        if(dp[to] != -1)
        {
            dp[x] = max(dp[x],1+dp[to]);
        }
        else
            dp[x] = max(dp[x],1+Solve(to));
    }
    R dp[x];
}

int main()
{

    SPEED;
    cin >> n >> m;
    int a,b;
    for(int i=0;i<m;i++)
    {
        cin >> a >> b;
        Adj[a].pb(b);
    }
    Mdp;
    for(int i=1;i<=n;i++)
        Solve(i);
    int Ans = 0;
    for(int i=1;i<=n;i++)
        Ans = max(Ans,dp[i]);

    cout << Ans-1 << endl;

    R 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x; cin >> x;
    int i = 0;
    ll tmp = 100;
    while (tmp < x) {
        tmp += tmp / 100;
        i++;
    }
    cout << i << '\n';
    return 0;
}


Measured memory_bytes: 3668
// abc047_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, T;
    cin >> N >> T;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    set<int> st(ALL(A));

    int cnt = 0;
    int mx_diff = 0;
    REP(i, N){
        int mx = *st.rbegin();
        int diff = mx - A[i];
        if (diff > mx_diff){
            mx_diff = diff;
            cnt = 1;
        } else if (diff == mx_diff){
            cnt++;
        }
        st.erase(A[i]);
//        print(st);
    }
    print(cnt);

    return 0;
}


Measured memory_bytes: 5376
package main
import (
	"fmt"
	"strconv"
)


func main(){
    // Your code here!
    var n int
    cnt := 0
    fmt.Scan(&n)
    
    for i := 1; i <= n; i++ {
		dgt := len(strconv.Itoa(i))
		if dgt % 2 != 0 {
			cnt++
		}
 	}
    fmt.Println(cnt)
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    double R; cin >> R;
    double ans=2*R*M_PI;
    cout << fixed << setprecision(10) << ans << endl;
}

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

int main(){
  int n, h, w;
  int counter = 0;
  std::cin >> n >> h >> w;
  
  for(int i=0;i<n;i++){
    int a, b;
    std::cin >> a >> b;
    counter += a >= h && b >= w;
  }
  
  std::cout << counter << std::endl;
  return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int a[100005]={0},b[100005]={0};
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n/2;i++)
	{
		int x,y;
		cin>>x>>y;
		a[x]++;
		b[y]++;
	}
	int maxa=0,maxb=0;
	int maxaa,maxbb;
	for(int i=1;i<=100000;i++)
	{
		if(maxa<a[i]) maxa=a[i],maxaa=i;
		if(maxb<b[i]) maxb=b[i],maxbb=i;
	}
	if(maxaa!=maxbb) cout<<(n-maxa-maxb)<<'\n';
	else
	{
		int maxaaa=0,maxbbb=0,maxaaaa,maxbbbb;
		for(int i=1;i<=100000;i++)
		{
			if(i!=maxaa && maxaaa<a[i]) maxaaa=a[i],maxaaaa=i;
			if(i!=maxbb && maxbbb<b[i]) maxbbb=b[i],maxbbbb=i;
		}
		if(maxaaa<maxbbb){
			cout<<n-maxa-maxbbb<<'\n';
		}
		else{
			cout<<n-maxaaa-maxb<<'\n';
		}
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	int a, b, t;
	cin >> a >> b >> t;
	cout << t / a * b << endl;
	
	return 0;
}

Measured memory_bytes: 256
N=int(input())
s=[int(x) for x in input().split()]

ans=0
for i in range(N-1):
    if s[i]>s[i+1]:
        ans+=(s[i]-s[i+1])
        s[i+1]=s[i+1]+(s[i]-s[i+1])
print(ans)

Measured memory_bytes: 31972
// どうやったら綺麗に書けるのかわからない
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

bool vis[1000] = {}, flag = false;
vector<int> tmp, cycle, v[1000];

void dfs(int i){
    tmp.push_back(i);
    if(vis[i]){
        flag = true;
        cycle.clear();
        cycle.push_back(i);
        for(int j = tmp.size()-2; tmp[j] != i; j--)   cycle.push_back(tmp[j]);
        return;
    }
    vis[i] = true;
    for(int j : v[i]){
        dfs(j);
        if(flag)    return;
    }   
    vis[i] = false;
    tmp.pop_back();
}

bool ng(vector<int> &v){
    // 実装をさぼっているので相当遅い
    vector<int> indeg(1000, 0);
    for(int i : v){
        for(int j : ::v[i]){
            indeg[j]++;
        }
    }
    for(int i : v)  if(indeg[i] > 1)    return true;
    return false;
}

vector<int> reduce(const vector<int> &v){
    vector<int> ret;
    int n = v.size();
    vector<bool> d(1000, 0);
    for(int i : v)  d[i] = true;
    for(int i = 0; i < v.size(); i++){
        int k = -1;
        for(int j : ::v[v[i]]){
            if(d[j] && v[(i+1)%n] != j){
                k = j;
                break;
            }
        }
        if(k == -1) continue;
        bool f = false;
        for(int j = (i+1)%n;; j = (j+1)%n){
            if(v[j] == k)   f = true;
            if(f){
                ret.push_back(v[j]);
                if(v[j] == v[i])   return ret;
            }
        }
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    while(m-- > 0){
        int x, y;
        cin >> x >> y;
        v[--x].push_back(--y);
    }
    for(int i = 0; i < n; i++){
        dfs(i);
        if(flag)    break;
    }
    if(!flag){
        cout << -1 << endl;
        return 0;
    }
    reverse(cycle.begin(), cycle.end());
    while(ng(cycle)){
        cycle = reduce(cycle);
    }
    cout << cycle.size() << endl;
    for(int i : cycle)  cout << i+1 << endl;
    return 0;
}

Measured memory_bytes: 384
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;cin>>s;
	int co=0;
	rep(i,s.size())if(s[i]=='1')co++;
	cout<<co<<endl;
}








Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;

inline int read()
{
   int x=0,f=1;char ch=getchar();
   while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
   while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
   return x*f;
}

const int maxn = 1e6+1e2;

struct Node{
	int vis[410];
};

int x[maxn],y[maxn];
Node a[410];
int n,m;
int ans;
int tag[maxn];


int main()
{
  n=read(),m=read();
  for (int i=1;i<=m;i++)
    x[i]=read(),y[i]=read();
  for (int i=1;i<=n;i++)
  {
  	 a[i].vis[i]=1;
  	 for (int j=m;j>=1;j--)
	   {
  	       if ((!a[i].vis[x[j]]) && (!a[i].vis[y[j]])) continue;
		   if (a[i].vis[x[j]] &&a[i].vis[y[j]]) tag[i]=1;
		   a[i].vis[x[j]]=1;
		   a[i].vis[y[j]]=1;	
  	   }
  }
  for (int i=1;i<=n;i++)
  {
  	 for (int j=i+1;j<=n;j++)
  	 {
  	 	if (tag[i] || tag[j]) continue;
  	 	int k;
  	 	for (k=1;k<=n;k++)
  	 	  if (a[i].vis[k] && a[j].vis[k]) break;
  	 	if (k==n+1) ans++;
  	 }
  }
  cout<<ans;
  return 0;
}


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

using namespace std;

int main()
{
    vector <string> lunlun[10];
    vector <string> ans;

    lunlun[0].push_back("0");
    lunlun[0].push_back("1");
    lunlun[0].push_back("2");
    lunlun[0].push_back("3");
    lunlun[0].push_back("4");
    lunlun[0].push_back("5");
    lunlun[0].push_back("6");
    lunlun[0].push_back("7");
    lunlun[0].push_back("8");
    lunlun[0].push_back("9");

    for (int k = 1; k < 10; k++)
    {
        for (int i = 0; i <= 9; i++)
        {
            for (int j = 0; j < lunlun[k-1].size(); j++)
            {
                string t = lunlun[k-1][j];
                char c = t[0];
                int d = abs((c - '0') - i);

                if (d < 2)
                {
                    c = (char)(i + '0');
                    lunlun[k].push_back(c + t);
                }
            }
        }
    }

    for (int k = 0; k < 10; k++)
    {
        for (auto s: lunlun[k])
        {
            if (s[0] != '0')
                ans.push_back(s);
        }
    }
    
    int k;
    cin >> k;
    cout << ans[k-1] << "\n";

    return 0;
}

Measured memory_bytes: 22640
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,c;
  cin>>n>>c;
  int d[30][30];
  int color[3][30]={0};
  rep(i,c){
    rep(j,c){
      cin>>d[i][j];
    }
  }
  int a[500][500];
  rep(i,n){
    rep(j,n){
      cin>>a[i][j];
      color[(i+j+2)%3][a[i][j]-1]++;
    }
  }
  int ans=INF;
  int sum=0;
  rep(i,c){
    rep(j,c){
      if(i!=j){
	rep(k,c){
	  if(i!=k && j!=k){
	    sum=0;
	    rep(l,c){
	      sum+=color[0][l]*d[l][i];
	      sum+=color[1][l]*d[l][j];
	      sum+=color[2][l]*d[l][k];
	    }
	    ans=min(ans,sum);
	  }
	}
      }
    }
  }
  
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;
int const modulo = 998244353;
int fact[1 + nmax], quick[1 + nmax];

void gcd(int a, int b, int &x, int &y) {
  if(b == 0) {
    x = 1;
    y = 0;
  } else {
    gcd(b, a % b, x, y);
    int aux = x;
    x = y;
    y = aux - a/ b * y;
  }
}

int inverse(int number) {
  int x, y;
  gcd(number, modulo, x, y);
  x %= modulo;
  if(x < 0)
    x += modulo;
  return x;
}

void precompute() {
  fact[0] = 1;
  for(int i = 1;i <= nmax; i++)
    fact[i] = 1LL * fact[i - 1] * i % modulo;
  for(int i = 0; i <= nmax; i++)
    quick[i] = inverse(fact[i]);
}

/*
The paths have lengths:
a1, a2 ... ak
a1 + a2 + ... ak + empt = n

The number of solutions is
(n + k)! / ((a1 + 1)! * (a2 + 1)! * ... (ak + 1)!) * n! 
^
chosing the positions in permutations; ^ choosing the ids
*/

int const lgmax = 14;
class dp{
public:
  std::vector<int> vp;
  void setsize(int n) {
    vp.resize(n);
  }
  dp operator * (dp a) {
    dp result;
    int n = vp.size();
    result.setsize(n);
    for(int i = 0; i < n; i++)
      for(int j = 0; j < n - i; j++) {
        result.vp[i + j] += 1LL * vp[i] * a.vp[j] % modulo;
        if(modulo <= result.vp[i + j])
          result.vp[i + j] -= modulo;
      }
    return result;
  }
} powp[1 + lgmax];

int main() {
  precompute();

  std::string a, b;
  std::cin >> a >> b;
  int n = 0, k = 0;
  for(int i = 0; i < a.size(); i++) {
    if(a[i] == '1') {
      if(b[i] == '1')
        n++;
      else
        k++;
    }
  }
  if(k == 0) {
    std::cout << 1LL * fact[n] * fact[n] % modulo;
    return 0;
  }
  

  int lim = n + 1;
  powp[0].setsize(lim);
  for(int i = 0; i < lim; i++)
    powp[0].vp[i] = quick[i + 1];
  for(int i = 1; i < lgmax; i++)
    powp[i] = powp[i - 1] * powp[i - 1];
  dp result = powp[0];
  int k2 = k;
  k2--;
  for(int i = lgmax - 1; 0 <= i; i--) {
    if((1 << i) <= k2) {
      k2 -= (1 << i);
      result = result * powp[i];
    }
  }

  int total = 0;
  for(int i = 0; i < lim; i++) {
    total += 1LL * fact[n] * fact[n + k] % modulo * result.vp[i] % modulo;
    if(modulo <= total)
      total -= modulo;
  }
  std::cout << 1LL * total * fact[k] % modulo;
  return 0;
}


Measured memory_bytes: 4864
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int x = scan.nextInt();
    int t = scan.nextInt();
    if (n%x == 0){
      System.out.println(n/x*t);
    }else{
      System.out.println((n/x+1)*t);
    }
  }
}


Measured memory_bytes: 35576
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>

#define repd(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int mod=pow(10,9)+7;

int dp[101][4][4][4];

int main(){
	//source
	int N=inputValue();
	dp[0][3][3][3]=1;
	rep(len,N){
		rep(c1,4){
			rep(c2,4){
				rep(c3,4){
					if(dp[len][c1][c2][c3]==0) continue;
					rep(n,4){
						if(n==2 && c1==1 && c2==0) continue;
						if(n==2 && c1==0 && c2==1) continue;
						if(n==1 && c1==2 && c2==0) continue;
						if(n==2 && c1==1 && c3==0) continue;
						if(n==2 && c2==1 && c3==0) continue;


						dp[len+1][n][c1][c2]+=dp[len][c1][c2][c3];
						dp[len+1][n][c1][c2]%=mod;
					}
				}
			}
		}
	}
	int ans=0;

	rep(c1,4){
		rep(c2,4){
			rep(c3,4){
				ans += dp[N][c1][c2][c3];
				ans %=mod;
			}
		}
	}

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


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    set<int> se;

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

    se.insert(a);
    se.insert(b);
    se.insert(c);

    cout << se.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(d >= abs(c-a) || (d >= abs(b-a) && d >= abs(c-b)))
    cout << "Yes" << endl;
    else 
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;

int n,m;
int miti[10][10];
int ans;

signed main(){
  cin >> n>> m;
  REP(i,m){
    int a1,b1;
    cin >> a1 >> b1;
    miti[a1][b1] = 1;
    miti[b1][a1] = 1;
  }
  vector<int> v;
  REP(i,n){
    v.pb(i+1);
  }
  do {
    int f = 1;
    if(v[0]!=1) f=0;
    REP(j,v.size()-1){
      if(miti[v[j]][v[j+1]]==0) f=0;
    }
    if (f==1) ans ++;
  } while(next_permutation(v.begin(), v.end()));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int n, k; cin >> n >> k;

    deque<int> dq_original;
    int negcnt = 0;
    for(int i=0; i<n; i++){
        int v; cin >> v;
        dq_original.push_back(v);
        if(v < 0){
            negcnt++;
        }
    }


    long long ans = 0;
    for(int i=1; i<=k; i++){
        int kpop  = i;
        int kpush = k-i;

        if(kpop > n) continue;
        if(kpush > negcnt) kpush = negcnt;
        
        deque<int> dq;
        vector<int> vhand;
        for(int j=0; j<=kpop; j++){
            dq = dq_original;
            vhand.clear();
            int kpopleft = j;
            int kpopright = kpop - j;

            for(int jl=0; jl<kpopleft; jl++){
                int temp = dq.front();
                dq.pop_front();
                vhand.push_back(temp);
            }
            for(int jr=0; jr<kpopright; jr++){
                int temp = dq.back();
                dq.pop_back();
                vhand.push_back(temp);
            }

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

            // cout << "kpopL: " << kpopleft << " kpopR: " << kpopright << " kpush: " << kpush << endl;
            // for(int t=0; t<vhand.size(); t++){
            //     cout << vhand[t] << " ";
            // }
            // cout << endl;

            // for(int t=0; t<vhand.size(); t++){
            //     cout << vhand[t] << " ";
            // }
            // cout << endl;

            int jpend = (kpush < vhand.size() ? kpush : vhand.size());
            for(int jp=0; jp<jpend; jp++){
            // cout << "here" << endl;
                if(vhand[0] < 0){
                    vhand.erase(vhand.begin());
                }
                else{
                    break;
                }
            }

            // for(int t=0; t<vhand.size(); t++){
            //     cout << vhand[t] << " ";
            // }
            // cout << endl;

            long long temp = accumulate(vhand.begin(), vhand.end(), 0LL);
            if(ans < temp){
                ans = temp;
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

void create_map(map< pair<string, string>, int> &mp, string s, int rev) {
    int N = s.length();

    for(int bit=0; bit<(1<<N); bit++) {
        string A = "", B = "";
        for(int i=0; i<N; i++) {
            if(bit >> i & 1) {
                A += s[i];
            }
            else {
                B = s[i] + B;
            }
        }

        pair<string, string> res;
        if(rev == 0) res = make_pair(A, B);
        if(rev == 1) res = make_pair(B, A);
        mp[res]++;
    }
}
 
signed main() {
    // len: 2N
    int N; string s; cin >> N >> s;

    map< pair<string, string>, int > mp1, mp2;
    create_map(mp1, s.substr(0, N), 0);
    create_map(mp2, s.substr(N, N), 1);

    int ans = 0;
    for(auto x : mp1) {
        if(!mp2.count(x.first)) continue;
        int vl = x.second, vr = mp2[x.first];
        ans += vl * vr;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 87040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please



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

	
	int N, L;
	cin >> N >> L;

	int goukei = 0;
	rep(i, N) {
		goukei += L + i;
	}

	if (L + N - 1 < 0) goukei -= L + N - 1;
	else if (L > 0) goukei -= L;
	co(goukei);


	Would you please return 0;
}

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

int main(){
    int S, h, m, s;
    cin >> S;
    h = S/3600;
    m = (S - h*3600)/60;
    s = S - h*3600 - m*60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3104
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 ln         PIC X(42).
01 A          PIC 9(19).
01 B          PIC 9(19).
01 K          PIC 9(19).
01 mna        PIC 9(19).
01 mnb        PIC 9(19).
01 ans        PIC X(40).
01 zsa        PIC Z(18)9.
01 zsb        PIC Z(18)9.

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO A B K.
  COMPUTE mna = FUNCTION MIN(A, K).
  COMPUTE A = A - mna.
  COMPUTE mna = K - mna.
  COMPUTE mnb = FUNCTION MIN(B, mna).
  COMPUTE B = B - mnb.
  MOVE A TO zsa.
  MOVE B TO zsb.
  STRING FUNCTION TRIM(zsa) SPACE FUNCTION TRIM(zsb) INTO ans.
  DISPLAY FUNCTION TRIM(ans).
  STOP RUN.


Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "YES" : "NO");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  bool is_ok = false;
  for (int i = A; i < 1e6; i += A)
  {
    if (i % B == C)
      is_ok = true;
  }
  printYesNo(is_ok);
  return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        int mod = 1000000000 + 7;
        var N = ConsoleUtil.IntReadLine();
        

        var primes = GetPrimeNumbers().TakeWhile(n => n <= N).ToArray();
        var counter = new int[primes.Length];

        for(int i = 1; i <= N; i++)
        {
            Count(i, primes, counter);
        }

        long ans = 1;
                
        for(int i = 0; i < counter.Length; i++)
        {
            ans *= (counter[i] + 1);
            ans %= mod;
        }

        Console.WriteLine(ans);
    }

    static void Count(int n, int[] primes, int[] counter)
    {
        for(int i = 0; i < primes.Length; i++)
        {
            int nCpy = n;
            int prime = primes[i];

            while(nCpy % prime == 0)
            {
                nCpy /= prime;
                counter[i]++;
            }
        }
    }

    static IEnumerable<int> GetPrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };

        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}



static class ConsoleUtil
{
    public static string[] StrArrayReadLine(char sepalator)
    {
        string str = Console.ReadLine();
        return str.Split(sepalator).ToArray();
    }
    public static string[] StrArrayReadLine()
    {
        string str = Console.ReadLine();
        if (str.Contains(','))
        {
            return str.Split(',').ToArray();
        }
        {
            return str.Split(' ').ToArray();
        }
    }
    
    public static int[] IntArrayReadLine()
    {
        return StrArrayReadLine().Select(s => int.Parse(s)).ToArray();
    }
    public static int[] IntArrayReadLine(char sepalator)
    {
        return StrArrayReadLine(sepalator).Select(s => int.Parse(s)).ToArray();
    }

    public static int IntReadLine() => int.Parse(Console.ReadLine());
}

Measured memory_bytes: 13268
from operator import itemgetter
import math

n, h = map(int, input().split())
ab = []
A = 0
B = 1
maxA = 0
for i in range(n):
    ab.append(list(map(int, input().split())))
    maxA = max(maxA, ab[i][A])

ab.sort(key=itemgetter(B), reverse=True)

sumB = 0
for _ab in ab:
    sumB += _ab[B]

ans = 0
damage = 0
i = 0
while damage < h and ans < n:
    damage += max(maxA, ab[ans][B])
    ans += 1

if damage < h:
    ans += math.ceil((h - damage)/maxA)

print(ans)

Measured memory_bytes: 29024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    char A,B,C;
    A = a[0]-32;
    B = b[0]-32;
    C = c[0]-32;
    cout << A << B << C << endl;
    return 0;
}

Measured memory_bytes: 256
#include "algorithm"
#include "iostream"
#include "cmath"
#include "string"
#include "map"
using namespace std;


int main(){
  while(true){
    int n,p;
    cin >> n >> p;
    if(!n&&!p)break;
    int a[n]={0};
    int wan=p,i;
    for(i=1;i<1000001;++i){
      if(wan==0){
        wan+=a[i%n];
        a[i%n]=0;
      }else {
        --wan;
        ++a[i%n];
        if(a[i%n]==p)break;
      }
    }
    cout << (i-1)%n <<endl;
  }
  return 0;
}

Measured memory_bytes: 3008
import itertools
n,m,x=map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(n)]
P = list(itertools.product([0,1], repeat=n))

MIN=10000000000
for p in P:
    ans = 0
    now = [0]*m
    for i in range(n):
        if p[i]==1:
            ans += ca[i][0]
            for g in range(1,m+1):
                now[g-1] += ca[i][g]
    frag = True
    for i in range(m):
        if now[i]<x:
            frag = False
            break
    if frag:
        MIN = min(ans,MIN)

if MIN == 10000000000:
    print(-1)
else:
    print(MIN)

Measured memory_bytes: 9652
#include <bits/stdc++.h>
#include <iostream>
#define lli long long int

using namespace std;

int main()
{
    lli n;
    cin>>n;
    lli a[n],i,j,k,diag=n-1,dp[n][n],sum[n+1];
    for(i=0;i<n;i++)
        cin>>a[i];
    sum[0]=0;
    for(i=1;i<=n;i++)
        sum[i]=sum[i-1]+a[i-1];
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(j>i)
                dp[i][j]=1e18;
            else
                dp[i][j]=0;
        }
    }
    for(i=0;i<diag;i++)
    {
        for(j=n-diag;j<n;j++)
        {
            for(k=i;k<j;k++)
                dp[i][j]=min(dp[i][k]+dp[k+1][j],dp[i][j]);
            dp[i][j] +=sum[j+1]-sum[i];
            i++;
        }
        diag--;
        i=-1;
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}


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

int main()
{
    int S;
    cin >> S;
    int a,b;
    a = S%3600;
    b = a%60;
    int c,d,e;
    c = S / 3600;
    d = a / 60;
    e = b;
    cout << c << ":" << d << ":" << e << endl;
    
    return 0;
    
    
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string s;
    cin>>s;
    int cnt=0;
    rep(i,s.size())if(s[i]!="CODEFESTIVAL2016"[i])cnt++;
    cout<<cnt<<endl;
    return 0;
}


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

int main() {
  vector<int> n(4);
  for (int i = 0; i < 4; i++) cin >> n[i];
  sort(n.begin(), n.end());
  if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min} ;

fn main() {
    input! {
        v: [i32; 5],
    }
    let sum: i32 = v.iter().map(|&x| { 10*((x + 9)/10)} ).sum();
    println!("{}", sum - v.iter().map(|&x| { 10*((x + 9)/10) - x }).max().unwrap());
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
int main(){
	string x;
	int y;
	while(cin>>x && x!="0"){
		y = 0;
		for(int i = 0,l = x.size();i<l;i++) y += x[i]-'0';
		cout<<y<<endl;
	}
}


Measured memory_bytes: 3208
K = int(input())

from collections import deque

def dfs():
    ans = set()

    tmp = deque([str(n) for n in range(1,10)])
    ans = set()
    while len(ans) <= 10 ** 5 + 1000:
        num = tmp.popleft()
        ans.add(int(num))
        if num[-1] == "0":
            tmp.append(num + "0")
            tmp.append(num + "1")
        elif num[-1] == "9":
            tmp.append(num + "8")
            tmp.append(num + "9")
        else:
            tmp.append(num + str(int(num[-1]) - 1))
            tmp.append(num + str(int(num[-1])))
            tmp.append(num + str(int(num[-1]) + 1))
    
    return list(ans)

ans = dfs()
ans.sort()
print(ans[K - 1])

Measured memory_bytes: 25212
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int n,i,j=0,k=0;
    char op[100],ch[100],sh[200];
    scanf("%d",&n);
    scanf("\n");
    for(i=0;i<n;i++)
    scanf("%c",&op[i]);
    op[i]='\0';
    getchar( );
    for(i=0;i<n;i++)
    scanf("%c",&ch[i]);
    ch[i]='\0';
    for(i=0;i<2*n;i++){
        if(i%2==0)
        {
            sh[i]=op[k];
            k++;
        }
        else
        {
            sh[i]=ch[j];
            j++;
        }
    }
    sh[i]='\0';
    printf("%s",sh);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using i64 = long long;



int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  int res=1000;
  do {
    res=min(res,abs(a[2]-a[1])+abs(a[1]-a[0]));
  } while (next_permutation(a,a+3));
  cout<<res<<"\n";
}


Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]

max_a = max(a)
if a.count(max_a) > 1:
    for i in range(n):
        print(max_a)
else:
    sec_max = sorted(a)[-2]
    max_i = a.index(max_a)
    for i in range(n):
        if i == max_i:
            print(sec_max)
        else:
            print(max_a)

Measured memory_bytes: 13384
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{

  int h, w;
  cin >> h >> w;
  int a, b;
  cin >> a >> b;

  cout << (h * w) - (b*h+a*w - a*b) << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

struct block {
    int w, s, val;
    
    bool operator < (const block &o) const {
        return w + s > o.w + o.s;
    }
};

const int N = 1e3+5;
const int S = 1e4+5;
block v[N];
ll dp[N][S];
int n;

ll go(int id, int cap) {
    if (id == n) return 0;
    ll &ans = dp[id][cap];
    if (ans != -1) return ans;
    
    ans = go(id+1, cap);
    if (v[id].w <= cap) {
        int ncap = min(cap-v[id].w, v[id].s);
        ans = max(ans, go(id+1, ncap) + v[id].val);
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> n;
    forn(i, 0, n) {
        int a, b, c;
        cin >> a >> b >> c;
        v[i] = {a, b, c};
    }
    
    sort(v, v+n);
    memset(dp, -1, sizeof dp);
    
    ll ans = 0;
    forn(i, 0, n) {
        ans = max(ans, go(i+1, v[i].s) + v[i].val);
    }
    cout << ans << endl;
}


Measured memory_bytes: 82220
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <numeric>
#include <vector>

using LL = long long;
const int kN = 200000 + 5;
const LL inf = 1e17;
int n, d;
int a[kN];
int group[kN];

int find(int x) {
  return group[x] == x ? x : group[x] = find(group[x]);
}

int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; ++ i) {
    scanf("%d", a + i);
  }
  std::iota(group, group + n, 0);
  LL result = 0;
  while (true) {
    if ([&]() {
      for (int i = 1; i < n; ++ i)
        if (find(i) != find(0))
          return false;
      return true;
    }()) {
      break;
    }
    using Pair = std::pair<LL, int>;
    using Set = std::set<Pair>;
    std::vector<Set> incs(n), decs(n);
    Set inc, dec;
    for (int i = 0; i < n; ++ i) {
      int g = find(i);
      incs[g].emplace(a[i] + i * 1LL * d, i);
    }
    for (int g = 0; g < n; ++ g) if (!incs[g].empty()) {
      inc.emplace(incs[g].begin()->first, g);
    }
    std::vector<Pair> bests(n, std::make_pair(inf, -1));
    for (int i = 0; i < n; ++ i) {
      int g = find(i);

      inc.erase(std::make_pair(incs[g].begin()->first, g));
      incs[g].erase(std::make_pair(a[i] + i * 1LL * d, i));
      if (!incs[g].empty()) {
        inc.emplace(incs[g].begin()->first, g);
      }

      if (!decs[g].empty()) {
        dec.erase(std::make_pair(decs[g].begin()->first, g));
      }
      decs[g].emplace(a[i] + (n - 1 - i) * 1LL * d, i);
      dec.emplace(decs[g].begin()->first, g);

      if (!inc.empty()) {
        auto it = inc.begin();
        if (it->second == g) ++ it;
        if (it != inc.end()) {
          int p = it->second;
          int j = incs[p].begin()->second;
          LL cost = a[i] + a[j] + std::abs(i - j) * 1LL * d;
          bests[g] = std::min(bests[g], std::make_pair(cost, p));
        }
      }
      if (!dec.empty()) {
        auto it = dec.begin();
        if (it->second == g) ++ it;
        if (it != dec.end()) {
          int p = it->second;
          int j = decs[p].begin()->second;
          LL cost = a[i] + a[j] + std::abs(i - j) * 1LL * d;
          bests[g] = std::min(bests[g], std::make_pair(cost, p));
        }
      }
    }
    for (int g = 0; g < n; ++ g) if (bests[g].second != -1) {
      int a = find(g);
      int b = find(bests[g].second);
      if (a != b) {
        result += bests[g].first;
        group[a] = b;
      }
    }
  }
  printf("%lld\n", result);
}

Measured memory_bytes: 48640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	if(x*4>=y&&y>=2*x)
	{
      //2a+4b=y
      //a+b=x;
      int a=(4*x-y);
      int b=(y-2*x);
      if(a%2==0&&b%2==0)
      {
      cout<<"Yes\n";
      }
      else
      {
      cout<<"No\n";
      }


	}
	else
	{
	cout<<"No\n";
	}
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());

        int[] times = new int[N];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            times[i] = Integer.parseInt(scanner.next());
            sum += times[i];
        }

        int M = Integer.parseInt(scanner.next());
        int[][] drinks = new int[M][2];
        for (int i = 0; i < M; i++) {
            int index = Integer.parseInt(scanner.next()) - 1; // 0基準にする
            int v = Integer.parseInt(scanner.next());

            drinks[i][0] = index;
            drinks[i][1] = v;
        }
        scanner.close();

        for (int i = 0; i < M; i++) {
            int timeIndex = drinks[i][0];
            int time = times[timeIndex];
            int newTime = drinks[i][1];

            System.out.println(sum - time + newTime);
        }
    }
}


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


#define mp make_pair
#define pb push_back
#define rep(i,port,sail) for(i=port;i<=sail;i++)
const int N = 100010;
typedef long long ll;
ll v[N],dp[N],w[N];
int main()
{
	int n,i,j,k,t;
	ll W;
	cin>>n>>W;
	rep(i,1,n)cin>>w[i]>>v[i];
	ll mx = 0;
	rep(i,1,100000)dp[i]=1e18+2;
	rep(i,1,n)
	{
		for(int j=100000;j>=v[i];j--)
		{
			dp[j]= min(dp[j],dp[j-v[i]]+w[i]);
		}
	}
	for(int j=100000;j>=0;j--)
	{
		if(dp[j]<=W){
			cout<<j<<"\n";break;}
	}


	
	return 0;
}



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

void colorEdges(int ptr, vector<vector<pair<int, int> > >& gra,
				vector<int>& edgeColors, bool isVisited[])
{
	queue<int> q;
	int c = 0;

	set<int> colored;

	if (isVisited[ptr])
		return;

	isVisited[ptr] = 1;

	for (int i = 0; i < gra[ptr].size(); i++) {
		if (edgeColors[gra[ptr][i].second] != -1)
			colored.insert(edgeColors[gra[ptr][i].second]);
	}

	for (int i = 0; i < gra[ptr].size(); i++) {
		if (!isVisited[gra[ptr][i].first])
			q.push(gra[ptr][i].first);

		if (edgeColors[gra[ptr][i].second] == -1) {
			while (colored.find(c) != colored.end())

				c++;

			edgeColors[gra[ptr][i].second] = c;

			colored.insert(c);
			c++;
		}
	}
	MAXCOLOR = max(MAXCOLOR,c);

	while (!q.empty()) {
		int temp = q.front();
		q.pop();

		colorEdges(temp, gra, edgeColors, isVisited);
	}

	return;
}

int main()
{
	set<int> empty;

	vector<vector<pair<int, int> > > gra;

	vector<int> edgeColors;

	bool isVisited[100001] = { 0 };

  int n; cin>>n;
	int ver = n;
	int edge = n-1;

	gra.resize(ver);
	edgeColors.resize(edge, -1);

	for(int i=0; i<n-1; ++i){
		int u,v;
		cin>>u>>v;
		u--; v--;
		gra[u].push_back({v,i});
		gra[v].push_back({u,i});
	}
	colorEdges(0, gra, edgeColors, isVisited);
	cout<<MAXCOLOR<<'\n';
	for (int i = 0; i < edge; i++)
			cout << edgeColors[i] + 1 << "\n";

	return 0;
}


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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const long long mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int sum = 0;
    rep(i, n) sum = (sum + a[i]) % mod;
    int ans = 0;
    rep(i, n-1) {
        sum = (sum - a[i] + mod) % mod;
        ans = (ans + (ll)a[i] * sum) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

struct node {
	ll to, index;
};

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, k; cin >> n >> k;
	vl a(n);
	REP(i, n) {
		cin >> a[i];
		a[i]--;
	}
	ll ans = 0;
	if (a[0] != 0) {
		ans++;
	}
	vvl rev_path(n);
	FOR(i, 1, n) rev_path[a[i]].push_back(i);
	function<ll(ll,ll)> dfs = [&](ll cur, ll depth) {
		if (rev_path[cur].empty()) {
			if (k == 1 && depth > 1) {
				ans++;
				return 0ll;
			}
			return 1ll;
		}
		ll ma = 1;
		for (auto next : rev_path[cur]) ma = max(ma, dfs(next, depth+1) + 1);
		if (k == ma && depth > 1) {
			ans++;
			return 0ll;
		}
		return ma;
	};
	dfs(0, 0);

	cout << ans << endl;
}

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

 
int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int h_n = n/2;
  int ans = a[h_n]-a[h_n-1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640