akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

const int MAX = 10000;


enum col
  {
   WHITE = 0,
   GRAY =  1,
   BLACK = 2,
  };

using namespace std;
const int INF = 0x7fffffff;

//int M[MAX][MAX];
col color[MAX];
int d[MAX];
int p[MAX];
int n;

vector<pair<int,int>> adj[MAX];


void daikusutora(int s){
  int ii,v;
  priority_queue<pair<int,int>> PQ;
  //初期化
  for(ii=0;ii<n;ii++){
    color[ii] = WHITE;
    d[ii] = INF;
    p[ii] = -1;
  }
  
  d[s] = 0;
  p[s] = -1;

  PQ.push(make_pair(s,0));
  
  int mincost,u;
  while(!PQ.empty()){


    //次に選ぶ頂点の決定
    pair<int,int> f = PQ.top();
    PQ.pop();
    u = f.second;

    color[u] = BLACK;
    //cout << "color:" << u << endl;
    if(d[u] < f.first * (-1)) continue;
    
    //次のパスの選択候補
    for(ii = 0; ii < adj[u].size(); ii++){
      v = adj[u][ii].first;
      if(color[v] == BLACK){ continue;}
      if(d[v] > d[u] + adj[u][ii].second){
        d[v] = d[u] + adj[u][ii].second;
        PQ.push(make_pair(d[v] * (-1),v));
        color[v] = GRAY;
      }
    }
    
  }


  
}

int main(){

  long ii,jj,kk;
  int u,k,v,c;
  vector<int> a;

  cin >> n;

  
  for(ii=0;ii<n;ii++){

    cin >> u >> k;
    //cout << "u:" << u << "k:" << k << endl;
    for(jj=0;jj<k;jj++){
      cin >> v >> c;
      adj[u].push_back(make_pair(v,c));
    }
    
  }


  daikusutora(0);

  for(ii=0;ii<n;ii++){
    cout << ii << " " << d[ii] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 8084
import java.io.*;
import java.util.Arrays;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		int[] input = Arrays.stream(stdin.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		IntStream.rangeClosed(input[0], input[1])
		.filter(i ->{
			int order = i - input[0];
			if(order < input[2]|| input[1] - input[0] - input[2]< order) return true;
			else return false;
		})
		.forEach(System.out::println);
	}
}

Measured memory_bytes: 28372
N = int(input())
A = list(map(int, input().split()))

INF = 10**9
min_cost = INF

for target in range(min(A), max(A)+1):
    tmp_cost = 0
    for i in range(N):
        tmp_cost += (target-A[i])**2
    if tmp_cost <= min_cost:
        min_cost = tmp_cost

print(min_cost)


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{

    long l;
    scanf("%ld", &l);
    long r;
    scanf("%ld", &r);

    long n = r-l+1;
    if (2019 < n)
        printf("%d\n", 0);
    else{
        long r = l%2019;
        long min = 2019;
        for (int c=r; c < r+n-1; c++){
            for (int d=c+1; d < r+n; d++){
                if((c*d)%2019 < min)
                    min = (c*d)%2019;
            }
        }
        printf("%ld\n", min);
    }




    return 0;
} 



Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define input freopen("input.txt", "r", stdin);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);



#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll x, k, d, pos=LLONG_MAX, neg=LLONG_MAX;
    cin>>x>>k>>d;
    if(x==0){
        if(k%2) cout<<d;
        else cout<<0;
    }
    else{
        x = abs(x);
        ll m = x%d;
        ll c = (x-m)/d;
        ll mv = max(0ll, k-c);
        x=x-(k-mv)*d;
        k=mv;
        if(k%2==0) pos = x;
        else pos = x-d;
        if(k>0){
            k--;
            if(k%2==0) neg = x-d;
            else neg = x;
        }
        ll ans = min(pos, neg);
        cout<<abs(ans);
    }
}


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

int main() {

  int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;
  if (( max({a,b,c,d,e}) - min({a,b,c,d,e}) ) <= k) cout << "Yay!" ;
  else cout << ":(";


}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(ll H, ll, vector<ll> A) {
  bool pred = H <= accumulate(ALL(A),0);
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll H;
  cin >> H;
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  solve(H, N, move(A));
  return 0;
}


Measured memory_bytes: 1024
#高橋君は、 N 個の競技プログラミング用の問題をつくりました。 
#それぞれの問題には 1 から N の番号がついており、問題 i の難易度は整数 di で表されます(大きいほど難しいです)。
#高橋君はある整数 K を決めることで、難易度が K 以上ならば「 ARC 用の問題」難易度が K 未満ならば「 ABC 用の問題」という風に、
#これらの問題を二種類に分類しようとしています。
#「ARC 用の問題」と「ABC 用の問題」が同じ数になるような整数 K の選び方は何通りあるでしょうか。
n = int(input())
d = sorted(map(int, input().split()))
m = n//2
print(d[m]-d[m-1])



Measured memory_bytes: 52804
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;
int n;

const int INF = 1 << 29;

int main(void)
{
	int pasta = INF;
	for (int i = 0; i < 3; i++)
	{
		int tmp;
		cin >> tmp;
		pasta = min(tmp, pasta);
	}
	int juice = INF;
	for (int i = 0; i < 2; i++)
	{
		int tmp;
		cin >> tmp;
		juice = min(tmp, juice);
	}
	cout << pasta + juice - 50 << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn=2e5+10;
const int INF=1e9;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair

struct node
{
	int l,r;
	node *ls,*rs;
	int mini;
} *root;
int n,a[maxn],q,pos;
int s[maxn];
pii p[maxn];
int dp[maxn];

void build(node *p,int l,int r)
{
	p->l=l;p->r=r;
	p->mini=INF;
	
	if (l==r) return;
	int mid=(l+r)>>1;
	p->ls=new node;
	p->rs=new node;
	build(p->ls,l,mid);
	build(p->rs,mid+1,r);
	return;
}

int getmin(node *p,int l,int r)
{
	if (l<=p->l && p->r<=r) return p->mini;
	else if (r<p->l || p->r<l) return INF;
	else return min(getmin(p->ls,l,r),getmin(p->rs,l,r));
}

void update(node *p,int pos,int val)
{
	if (p->l==p->r) 
	{
		p->mini=min(p->mini,val);
		return;
	}
	else
	{
		if (pos<=p->ls->r) update(p->ls,pos,val);
		else update(p->rs,pos,val);
		p->mini=min(p->ls->mini,p->rs->mini);
		return;
	}
}

int main() 
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d",&a[i]);
		s[i]=s[i-1]+(1-a[i]);
	}
	scanf("%d",&q);
	for(int i=1;i<=q;i++) scanf("%d%d",&p[i].x,&p[i].y);
	sort(p+1,p+q+1);
	
	root=new node;
	build(root,0,n);
	for(int i=1;i<=n;i++) dp[i]=INF;
	update(root,0,0);
	dp[0]=0;
	
	pos=1;
	for(int i=1;i<=n;i++)
	{
		dp[i]=min(dp[i],dp[i-1]+a[i]);
		
		int st=pos;
		while(pos<=q && p[pos].x==i) pos++;
		int ed=pos-1;
		
		for(int j=st;j<=ed;j++)
		{
			int tmp=min(dp[i-1]+s[p[j].y]-s[i-1],
				getmin(root,p[j].x,p[j].y-1)+s[p[j].y]);
			dp[p[j].y]=min(dp[p[j].y],tmp);
			update(root,p[j].y,tmp-s[p[j].y]);
		}
	}
	
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 24960
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int c, d;
	cin >> c >> d;
	int lower = max(a, c);
	int upper = min(b, d);
	cout << max(0, upper - lower) << endl;
	return 0;
}

Measured memory_bytes: 256
import std;
enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;}
T scan(T=long)(){return readln.chomp.to!T;}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);}
//END OF TEMPLATE

void main(){
    auto n=scan!size_t;
    switch(n%10){
        case 2,4,5,7,9:
            "hon".writeln;
            break;
        case 0,1,6,8:
            "pon".writeln;
            break;
        default:
            "bon".writeln;
    }
}


Measured memory_bytes: 3644
#include <iostream>
#include <array>

template <int N>
struct factorial {
    static const long long int value = N * factorial<N - 1>::value;
};

template <>
struct factorial<0> {
    static const long long int value = 1;
};

int main() {
    int n;
    std::array<long long int, 21> arr;
    arr[1] = factorial<1>::value;
    arr[2] = factorial<2>::value;
    arr[3] = factorial<3>::value;
    arr[4] = factorial<4>::value;
    arr[5] = factorial<5>::value;
    arr[6] = factorial<6>::value;
    arr[7] = factorial<7>::value;
    arr[8] = factorial<8>::value;
    arr[9] = factorial<9>::value;
    arr[10] = factorial<10>::value;
    arr[11] = factorial<11>::value;
    arr[12] = factorial<12>::value;
    arr[13] = factorial<13>::value;
    arr[14] = factorial<14>::value;
    arr[15] = factorial<15>::value;
    arr[16] = factorial<16>::value;
    arr[17] = factorial<17>::value;
    arr[18] = factorial<18>::value;
    arr[19] = factorial<19>::value;
    arr[20] = factorial<20>::value;
    
    std::cin >> n;
    std::cout << arr[n] << std::endl;

    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
	LL n; int s; scanf("%lld",&n);
	s=sqrt(n);
	for(LL i=s; i>=1; --i)
		if(n%i==0)return printf("%lld",n/i-1+i-1),0;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string a, b, c;
  cin>>a>>b>>c;
  cout<<"A"<<b[0]<<"C"<<endl;
}



Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
long long n,m,x,y,a[100005],ans,dp[100005];
vector<long long>v[100005];
long long dfs(long long i)
{
    if(dp[i]!=-1)
    return dp[i];
    for(int j=0;j<v[i].size();j++)
        dp[i]=max(dp[i],dfs(v[i][j])+1);
    return dp[i];
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<=n;i++)
    dp[i]=-1;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        x--;
        y--;
        v[x].push_back(y);
        a[y]=1;
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        ans=max(ans,dfs(i)+1);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 11904
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		String str = sc.next();

		int count = 0;

		for (int i = 0; i < str.length()/2; i++) {
			char a = str.charAt(i);
			char b = str.charAt(str.length() - i - 1);
			if (a != b)
				count++;

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

	}

}


Measured memory_bytes: 35716
#include<stdio.h>
#include<math.h>

typedef struct{
  double x;
  double y;
  }dot;

void koch(int,dot,dot);

int main(){
  int n;
  dot a;
  dot b;

  a.x=0.0; a.y=0.0;
  b.x=100.0; b.y=0.0;

  scanf("%d",&n);

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}

void koch(int n,dot p1,dot p2){
  dot s,u,t;

  if(n == 0) return;

  s.x= (2*p1.x + p2.x)/3;
  s.y= (2*p1.y + p2.y)/3;

  t.x= (p1.x + 2*p2.x)/3;
  t.y= (p1.y + 2*p2.y)/3;

  u.x= (t.x -s.x) * cos(M_PI/3) - (t.y-s.y) * sin(M_PI/3) + s.x;
  u.y= (t.x -s.x) * sin(M_PI/3) + (t.y-s.y) * cos(M_PI/3) + s.y;

  koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);

  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);

  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);

  koch(n-1,t,p2);
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll k;
	int ans=0;
	cin >>n>>k;
	VV tri(n, V(61));//st, at (2^n)
	rep(i, n) { cin >> tri[i][0];
		tri[i][0]--;
	}
	rep(i,61){
		if (i == 0) continue;
		rep(j, n) { tri[j][i] = tri[tri[j][i - 1]][i - 1]; }
	}
	//clog << tri << endl;
	int at = 0;
	for (int i = 0; (1LL <<i) <= k;i++){
	//	clog << i<<" "<<at << endl;
		if(k & (1LL<<i))at = tri[at][i];
	}
	 cout << at+1<< endl;
}

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


int main(){
  int n,l;
  std::cin>>n>>l;
  std::string s[n];
  int size=l;
  for(int i=0;i<n;i++){
    std::cin>>s[i];
  }


  for(int k=0;k<n-1;k++){
    for(int i=0;i<n-1;i++){
      for(int j=0;j<l;j++){
        if(s[i][j]<s[i+1][j]){
          break;
        }else if(s[i][j]>s[i+1][j]){
          std::string so=s[i];
          s[i]=s[i+1];
          s[i+1]=so;
          break;
        }
      }
    }
  }


  for(int i=0;i<n;i++){
    std::cout<<s[i];
  }
  std::cout<<""<<std::endl;



}



Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=100000007;
const ll INF=1000000101001;
int main(){
 int n,k;cin>>n>>k;
 int h[n];
 int cnt=0;
 rep(i,n){
     cin>>h[i];
     if(h[i]>=k)cnt++;
 }
 cout << cnt << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int Cin()
{
    int n;
    cin >> n;
    return n;
}

class MaxFlowCalc
{
private:
    // 辺を表す構造体
    struct Edge
    {
        int To;     // 行き先
        int Cap;    // 容量
        int Rev;    // 逆辺
    };

    int INF = 1000000000;
    
    // グラフ（隣接リスト表現）
    vector<vector<Edge>> m_graph;
    // DFSで既に調べたかどうかのフラグ
    vector<bool> m_usedFlags;

    // 深さ優先探索
    const int DFS(const int v, const int t, const int f)
    {
        if (v == t) return f;
        m_usedFlags[v] = true;
        for (Edge &edge : m_graph[v])
        {
            if (!m_usedFlags[edge.To] && edge.Cap > 0)
            {
                // 行先ノードをまだ使っておらず，容量も空いているならば
                // 流せるだけ流してみる
                const int d = DFS(edge.To, t, min(f, edge.Cap));
                if (d > 0)
                {
                    // 流せた場合の残余を計算
                    edge.Cap -= d;
                    m_graph[edge.To][edge.Rev].Cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

public:
    // コンストラクタ
    MaxFlowCalc(const int N)
    {
        m_graph = vector<vector<Edge>>(N);
        m_usedFlags = vector<bool>(N);
    }

    // 辺を追加
    void AddEdge(const int from, const int to, const int capacity)
    {
        Edge F, T;
        F.To = to;
        F.Cap = capacity;
        F.Rev = m_graph[to].size();
        m_graph[from].push_back(F);
        T.To = from;
        T.Cap = 0;
        T.Rev = m_graph[from].size() - 1;
        m_graph[to].push_back(T);
    }

    // 最大流を計算
    const int ComputeMaxFlow(const int source, const int target)
    {
        int flow = 0;
        for (;;)
        {
            // フラグ初期化
            for (auto itr = m_usedFlags.begin();
                itr != m_usedFlags.end(); ++itr) *itr = false;
            // 深さ優先探索でなるべくたくさん流す
            int f = DFS(source, target, INF);
            // これ以上流せなくなったら終了
            if (f == 0) return flow;
            flow += f;
        }
    }
};

int main()
{
    // 二部グラフの最大マッチング問題
    // 最大流問題として解く
    int N = Cin();
    vector<int> as(N), bs(N), cs(N), ds(N);
    for (int i = 0; i < N; ++i) cin >> as[i] >> bs[i];
    for (int i = 0; i < N; ++i) cin >> cs[i] >> ds[i];
    // Flow Networkを構築：ソース→赤→青→ターゲットとつなぐ
    MaxFlowCalc mfc(2 * N + 2);
    for (int r = 0; r < N; ++r) mfc.AddEdge(0, r + 1, 1);
    for (int b = 0; b < N; ++b) mfc.AddEdge(N + b + 1, 2 * N + 1, 1);
    for (int r = 0; r < N; ++r)
    {
        for (int b = 0; b < N; ++b)
        {
            if (as[r] < cs[b] && bs[r] < ds[b])
            {
                mfc.AddEdge(r + 1, N + b + 1, 1);
            }
        }
    }
    // 最大流＝最大マッチング数
    cout << mfc.ComputeMaxFlow(0, 2 * N + 1) << endl;
}


Measured memory_bytes: 384
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let k: usize = input();
    let mut a: Vec<i64> = (0..n).map(|_| input()).collect();
    a.sort();

    let mut v = vec![];
    let mut cnt = 1;
    for i in 1..n {
        if a[i] == a[i - 1] {
            cnt += 1;
        } else {
            v.push(cnt);
            cnt = 1;
        }
    }
    v.push(cnt);
    v.sort();

    let mut ans = 0;
    if v.len() > k {
        ans = v.iter().take(v.len() - k).sum::<i64>();
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n;
	cin>>n;
	int a[n];
	int xr=0;
	forci(0,n){
		cin>>a[i];
		xr=xr^a[i];
	}
	for(int i=0;i<n;i++){
		int ans=xr^a[i];
		cout<<ans<<" ";
	}
	cout<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}






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

using namespace std;

using ll = long long int;

int main() {
    // Input
    ll X;
    cin >> X;

    // Process
    int cnt = 0;
    ll x = 100;
    for (; x < X; x = (ll)(x * 1.01)) cnt++;

    // Output
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3636
a, b, c, x, y = map(int,input().split())
ans = 0

while x > 0 or y > 0:
    if x>0 and y>0:
        if 2*c<a+b:
            ans += 2*c
            x -= 1
            y -= 1
        else:
            ans = ans+a+b
            x -= 1
            y -= 1
    elif x>0:
        if 2*c<a:
            ans += 2*c
            x -= 1
        else:
            ans += a
            x -= 1
    else:
        if 2*c < b:
            ans += 2*c
            y -= 1
        else:
            ans += b
            y -= 1
#    print(ans)

print(ans)

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

int main(){
  int n;
  cin >> n;
  if(n == 22) puts("Christmas Eve Eve Eve");
  if(n == 23) puts("Christmas Eve Eve");
  if(n == 24) puts("Christmas Eve");
  if(n == 25) puts("Christmas");
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    vector<pii> V1;
    for (int i = 0; i < N; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        V1.push_back(make_pair(a, b));
    }
    sort(V1.begin(), V1.end());
    LL ans = 0;
    for (int i = 0; i < (int)V1.size() && M; i++) {
        LL need = min(M, V1[i].second);
        ans += need * V1[i].first;
        M -= need;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>

int main(){
	int a, b, c;
	int i;
	int ans = 0;
	scanf("%d %d %d", &a, &b, &c);

	for(i = a; i <= b ; i++ ){
		if(c % i == 0) ans++;
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
	vector<ll> rv(a);
	vector<ll> gv(b);
	vector<ll> lv(c);
	for( int i = 0; i < a; ++i ) cin >> rv[i];
	for( int i = 0; i < b; ++i ) cin >> gv[i];
	for( int i = 0; i < c; ++i ) cin >> lv[i];
	sort( rv.begin(), rv.end(), greater<ll>() );
	sort( gv.begin(), gv.end(), greater<ll>() );
	sort( lv.begin(), lv.end(), greater<ll>() );
	ll sum = 0;
	priority_queue<ll, vector<ll>, greater<ll>> r;
	priority_queue<ll, vector<ll>, greater<ll>> g;
	priority_queue<ll> l;
	for( int i = 0; i < x; ++i ){
		sum += rv[i];
		r.push(rv[i]);
	}
	for( int i = 0; i < y; ++i ){
		sum += gv[i];
		g.push(gv[i]);
	}
	for( int i = 0; i < c; ++i ){
		l.push(lv[i]);
	}
	// cout << sum << endl;
	while( !l.empty() ){
		if( l.top() - r.top() < 0 and l.top() - g.top() < 0 ) break;
		// 赤いリンゴから小さい方を捨てる
		if( r.top() < g.top() and l.top() - r.top() > 0 ){
			sum += ( l.top() - r.top() );
			// cout << "r.top(): " << r.top() << endl;
			r.pop();
			r.push(l.top());
		} else if( l.top() - g.top() > 0 ){
			sum += ( l.top() - g.top() );
			// cout << "g.top(): " << g.top() << endl;
			g.pop();
			g.push(l.top());
		} else break;
		l.pop();
	} 
	cout << sum << endl;
}

Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define ll long long
#define var auto
using namespace std;

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

int main(){
  ll p, q;
  cin >> p >> q;
  var g = gcd(p, q);
  p /= g;
  q /= g;
  ll res = 1;
  for (ll i = 2; i * i <= q; i++){
    if (q % i != 0) continue;
    res *= i;
    while (q % i == 0){
      q /= i;
    }
  }
    res *= q;
  cout << res << endl;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define N 100010
using namespace std;
vector<long long> vp[N];
priority_queue<long long> pq;
long long n,m,a,b,ans=0;
int main(){
	long long i,j,cnt;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a>m)
		{
			continue;
		}
		vp[a-1].push_back(b);
	}
	for(i=0;i<m;i++)
	{
		for(j=0;j<vp[i].size();j++)
		{
			pq.push(vp[i][j]);
		}
		if(pq.size())
		{	
			ans+=pq.top();
			pq.pop();
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
	int ans = 0;
	string s;
	cin >> s;
	stack<int> p;
	for(int i=0;i<s.length();i++)
	{
		int z = s[i] - '0';
		if(p.empty())
			p.push(z);
		else
		{
			if(p.top() + z == 1)
			{
				ans += 2;
				p.pop();
			}
			else p.push(z);
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

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

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N, M, X, Y; cin >> N >> M >> X >> Y;
  vector<int> x(N), y(M);
  rep(i, N) cin >> x[i];
  rep(i, M) cin >> y[i];
  x.push_back(X);
  y.push_back(Y);
  sort(x.begin(), x.end(), greater<int>());
  sort(y.begin(), y.end(), less<int>());
  if (y[0] - x[0] >= 1) cout << "No War" << endl;
  else cout << "War" << endl;
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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 x,a,b;
inline void solve(){
  IN3(x,a,b);
  OUT(abs(x-a)<abs(x-b)?'A':'B');
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
S = [input() for _ in range(H)]

dist = [[-1]*W for _ in range(H)]
dist[0][0]=1
d=deque()
d.append((0,0))

while d:
    pop = d.popleft()
    y, x = pop[0], pop[1]

    y_lst = [y+1, y-1, y, y]
    x_lst = [x, x, x+1, x-1]

    for Y, X in zip(y_lst, x_lst):
        if not (0 <= Y < H) or not (0 <= X < W) or S[Y][X]=="#":
            continue
        if dist[Y][X]==-1:
            dist[Y][X] = dist[y][x] + 1
            d.append((Y, X))

if dist[H-1][W-1]==-1:
    print(-1)
else:
    goaltime = dist[H-1][W-1]
    white_sum = 0
    for i in S:
        white_sum += i.count(".")
    print(white_sum-goaltime)


Measured memory_bytes: 9468
h, w = map(int, input().split())
l = [input() for i in range(h)]
l = [s for s in l if s.count("#") > 0]
check = [True] * w
for i in range(len(l[0])):
    check_row = True
    for j in range(len(l)):
        if l[j][i] == "#":
            check_row = False
    check[i] = check_row
ans = []
for i in range(len(l)):
    str_row = ""
    for j in range(len(l[0])):
        if not(check[j]):
            str_row += l[i][j]
    ans.append(str_row)
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll k;
	cin>>k;
	ll y = k%50;
	ll r = k/50;
	cout<<50<<endl;
	ll a[50];
	iota(a,a+50,r);
	for(int i = 50-y; i<50; i++)
		a[i]++;
	for(int i = 0;i<50; i++)
		cout<<a[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    long long A, B, C, K;
    cin >> A >> B >> C >> K;
    
//    for (int i {1}; i <= K; ++i) {
//        int a {A}, b{B}, c{C};
//        A = b + c;
//        B = a + c;
//        C = a + b;
//    }
    if (abs(A - B) > pow(10, 18)) {
        cout << "Unfair" << endl;
    } else {
        if (K % 2 == 0) {
            cout << A - B << endl;
        } else {
            cout << B - A << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,a[2005][2005];
const int M=1e9+7;
int main(){
	scanf("%d %d",&n,&k);
	a[0][1]=1;
	for(int i=1;i<=n;++i){
		for(int o=1;o<=n;++o){
			a[i][o]=a[i-1][o-1]+a[i-1][o];
			if(a[i][o]>=M)a[i][o]-=M;
		}
	}
	if(n==k&&k==1){
		cout<<"1";
		return 0;
	}
	n-=k-1;
	for(int i=1;i<=k;++i){
		printf("%d\n",1ll*a[k-1][i]*a[n][i+1]%M);
	}
}

Measured memory_bytes: 15872
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

#define L 394
int N, M;
int s[L], l[L], p[L], w[L];
int dp[L];

void solve(){
    Rep(i, 0, L) dp[i] = 0;
    Rep(i, 0, N){
        Rep(j, 0, L){
            Rep(k, s[i], l[i] + 1){
                if(j >= k) dp[j] = Max2(dp[j - k] + p[i], dp[j]);
            }
        }
    }
}

int main(){
    cin >> N;
    Rep(i, 0, N) cin >> s[i] >> l[i] >> p[i];
    cin >> M;
    Rep(i, 0, M) cin >> w[i];
    solve();
    Rep(i, 0, M){
        if((w[i] = dp[w[i]]) == 0){
            Print("-1");
            return 0;
        }
    }
    Rep(i, 0, M) Print(w[i]);
    return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define MAX_V 10000

int main(){
    int N;
    cin >> N;
    int lis[N + 1];
    for (int i = 1; i <= N; i++)
    {
        cin >> lis[i];
    }
    vector<ll> v(N);
    for (int i = 0; i < N; i++)
    {
        v[i] = lis[i + 1];
    }
    sort(v.begin(), v.end());
    /*for (int i = 0; i < N; i++){
        cout << v[i];
        cout << "\t";
    }
    cout << "\n";*/
    
    ll ans = 0;
    for(ll mid = N - 1; mid >= 0; mid--){
        for (ll low = mid - 1; low >= 0; low--){

            auto itr = lower_bound(v.begin(), v.end(), v[mid] + v[low]);
            ll ng = distance(itr, v.end());
            /*cout << mid;
            cout << "\t";
            cout << low;
            cout << "\t";
            cout << ng << endl;*/
            ans += (N - 1 - mid) - ng;
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]
i = 1
count = 0
btn = [1]
while(1):
  i = a[i-1]
  count += 1
  if count>n:
    print(-1)
    break
  if i == 2:
    print(count)
    break
  btn.append(i)

Measured memory_bytes: 7856
#include <iostream>
#include<iomanip>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>

#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
  string s;
  cin >> s;
  int l,count1=0,count2=0;
  l = (int)(s.length());
  
  
  rep(i,l){
    if(i%2 == 0){
      if(s[i] == '0'){
        count1++;
      }
    }
    if(i%2 == 1){
      if(s[i] == '1'){
        count1++;
      }
    }
  }
  rep(j,l){
    if(j%2 == 0){
      if(s[j] == '1'){
        count2++;
      }
    }
    if(j%2 == 1){
      if(s[j] == '0'){
        count2++;
      }
    }
  }
 
  cout << min(count1,count2);
  
 return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  // dp[i][j][k] :=  i回目の移動で強連結成分がj個
  // 連結かつ強連結成分に含まれないものなものがk個
  // できる操作
  // 1. 連結なものを強連結成分に移す
  // 2. 連結なものを1増やす
  // 3. 連結なものを増やさない

  ll n, m;std::cin >> n >> m;
  ll P = 1000000007;
  vvvl dp = VVV(m+1, n+1, n+1, 0);
  dp[0][1][0] = 1;

  for(ll i=0;i<m;i++){
    for(ll j=1;j<=n;j++){
      for(ll k=0;k<n;k++){
        //移す (すでに強連結成分に含まれるj個から選ぶ)
        if(j+k<=n){
          dp[i+1][j+k][0] = (dp[i+1][j+k][0]+(j*dp[i][j][k])%P)%P;
        }
        //連結なものを1増やす(選ばれていないn-j-k個から選ぶ)
        if(j+k<n) {
          dp[i+1][j][k+1] = (dp[i+1][j][k+1] + ((n-j-k)*dp[i][j][k])%P)%P;
        }
        //連結なものを増やさない
        dp[i+1][j][k] = (dp[i+1][j][k] + (k*dp[i][j][k])%P)%P;
      }
    }
  }
  std::cout << dp[m][n][0] << '\n';
  return 0;
}


Measured memory_bytes: 216832
from heapq import heapify, heappush, heappop
class HeapQue(object):
    def __init__(self, iterable, max_heap=False):
        self.sign = -1 if max_heap else 1
        sequence = [number * self.sign for number in iterable]
        heapify(sequence)
        self.heapque = sequence

    def push(self, item):
        heappush(self.heapque, item * self.sign)

    def pop(self):
        return heappop(self.heapque) * self.sign

    def dump(self):
        return [heappop(self.heapque) * self.sign for _ in range(len(self.heapque))]

N, M = map(int, input().split())
heap = HeapQue(map(int, input().split()), max_heap=True)
for _ in range(M):
    heap.push(heap.pop() >> 1)
print(sum(heap.dump()))


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

ll N;
ll ans = 0;

void solve() {
    cin >> N;
    if (N < 1000) cout << "ABC" << endl;
    else cout << "ABD" << endl;
}

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


Measured memory_bytes: 256
n = int(input())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append([a, b, a+b])


#%%
# n = 3
# ab = [
# [20, 10, 30],
# [20, 20, 40],
# [20, 30, 50]]


#%%
ab.sort(key=lambda x: -x[2])


    


#%%
takahashi = 0
for i in ab[0::2]:
    takahashi += i[0]

aoki = 0
for i in ab[1::2]:
    aoki += i[1]

#%%
print(takahashi - aoki)

#%%


Measured memory_bytes: 27728
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    int v[32] = {
        1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
    };
    int k; cin >> k;
    k--;
    print(v[k]);
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <stack>
#include <climits>

using namespace std;
int N,K;
vector< int > sassi;



int solve(){
	int DP[N];
	
	DP[0] = 0;
	//DP[1] = abs(sassi[1] - sassi[0]);
	
	for(int i=1; i < N; i++){
		int minimo = INT_MAX;
		for(int k=1; k < min(i+1,K+1) ; k++){
			int valore = DP[i-k] + abs(sassi[i] - sassi[i-k]);
			minimo = min(minimo,valore);
		}
		DP[i] = minimo;
	}
	
	return DP[N-1];
}


int main(int argc, char** argv) {
	cin >> N >> K;
	
	for(int i=0;i< N;i++){
		int p;
		cin >> p;
		sassi.push_back(p);
	}
	
	cout << solve();	
	return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
using vi = vector<int>;
template <class T>
using Grid = vector<vector<T>>;
const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x = 0)
        : x((x % mod + mod) % mod) {}
    mint operator-() const {
        return mint(-x);
    }
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        return mint(*this) += a;
    }
    mint operator-(const mint a) const {
        return mint(*this) -= a;
    }
    mint operator*(const mint a) const {
        return mint(*this) *= a;
    }
    mint pow(ll t) const {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a) {
        return *this *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream &operator>>(istream &is, const mint &a) {
    return is >> a.x;
}
ostream &operator<<(ostream &os, const mint &a) {
    return os << a.x;
}
std::string rsubstr(std::string str, size_t pos, size_t len = std::string::npos) {
    const size_t strlen = str.length();
    if ((std::string::npos == len) || ((pos + 1) < len)) {
        len = pos + 1;
    }
    std::string dst = str.substr(strlen - pos - 1, len);
    return dst;
}
int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> a;
    for (int bit = 0; bit < (1 << (W - 1)); bit++) {
        string s = bitset<7>(bit).to_string();
        if (s.find("11") != string::npos)
            continue;
        a.push_back("0" + rsubstr(s, W - 2) + "0");
    }
    Grid<mint> dp(H + 1, vector<mint>(W + 2, 0));
    dp[0][1] = 1;
    rep2(i, H) rep2(j, W) {
        ll l = 0, m = 0, r = 0;
        for (auto b : a) {
            if (b[j - 1] == '0' && b[j] == '0')
                m++;
            if (b[j - 1] == '1')
                l++;
            if (b[j] == '1')
                r++;
        }
        dp[i][j] = dp[i - 1][j - 1] * l + dp[i - 1][j] * m + dp[i - 1][j + 1] * r;
    }
    cout << dp[H][K] << endl;
}

Measured memory_bytes: 3656
def InsertionSort(l):
    print(" ".join(map(str, l)))
    
    for idx in range(1, len(l)):
        jdx = idx - 1
        while jdx >= 0 and l[idx] < l[jdx]:
            l[jdx], l[idx] = l[idx], l[jdx]
            idx -= 1
            jdx -= 1

        print(" ".join(map(str, l)))

def main():
    _ = input()
    in_list = list(map(int, input().split(' ')))
    
    InsertionSort(in_list)


main()


Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int a, b, h;
    cin >> a >> b >> h;
    int ans = (a + b) * (h / 2);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long ans;
int n,a,cnt,MIN=1000000007,ok,res;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        ans+=abs(a);
        MIN=min(MIN,abs(a));
        if(a<0){
            if(ok==0){
                ok=1;
                cnt++;
            }
            res++;
        }
        else if(a>0&&ok==1){
            ok=0;
            if(res%2==0)cnt--;
            res=0;
        }
    }
    if(res%2==0&&res>0)cnt--;
    if(cnt%2==1)ans-=2*MIN;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S,T;
    cin >> S >> T;
    vector<vector<int>> idx(26);
    REP(i,S.size()){
        idx[(S[i]-'a')].push_back(i+1);
    }
    ll ans = 0;
    int cur = 0;

    REP(i,T.size()){
        if(idx[T[i]-'a'].size() != 0){
            int next_idx = upper_bound(idx[T[i]-'a'].begin(),idx[T[i]-'a'].end(),cur) - idx[T[i]-'a'].begin();
            int next;
            if(next_idx == idx[T[i]-'a'].size()){
                next = idx[T[i]-'a'][0];
                ans += (int)S.size() - cur;
                cur = next;
                ans += cur;
            }
            else{
                next = idx[T[i]-'a'][next_idx];
                ans += next - cur;
                cur = next;
            }
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<int> a(n),b(n),c(m),d(m);
	rep(i,n) cin >> a.at(i) >> b.at(i);
	rep(i,m) cin >> c.at(i) >> d.at(i);
	vector<int> ans(n);
	rep(i,n){
		int mi = 1e9, k = 0;
		rep(j,m){
			if(abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j)) < mi){
				mi = abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j));
				k = j;
			}
		}
		ans.at(i) = k;
	}
	rep(i,n){
		cout << ans.at(i) + 1 << endl;
	}
}


Measured memory_bytes: 256
n, m = map(int, input().split())
A = [int(i) for i in input().split()]

A[0] %= m
for i in range(1, n):
    A[i] += A[i-1]
    A[i] %= m
    
from collections import Counter

count = 0
C = Counter(A)
for k, v in C.items():
    if k == 0:
        count += v
    if v >= 2:
        count += v * (v-1) // 2
        
print(count)

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

  $ans=0;
  for($i=1;$i<=$n;$i++){
    if($i%2===0){
      continue;
    }
    $cnt=0;
    for($j=1;$j<=$i;$j++){
      if($i%$j===0){
        $cnt++;
      }
    }
    if($cnt===8){
      $ans++;
    }
  }
  echo $ans;

Measured memory_bytes: 16336