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

using namespace std;
#define _for(i,j,N) for(int i = (j); i < (N);i++)
#define _rep(i,j,N) for(int i = (j); i <= (N);i++)
#define _dec(i,j,N) for(int i = (N-1);i >= 0;i--)
#define _dep(i,j,N) for(int i = (N); i>= 0;i--)
#define ALL(x) x.begin(),x.end()
#define LL long long
#define ULL unsigned LL
#define PB push_back

LL N;

int main()
{
    cin >> N;
    LL i = 1;
    //LL before = N;
    LL ans = 0;
    if(N == 2){

    }
    while(true){
        if(N/i - 1 <= i) break;
        if(N % i != 0) {i++;continue;}
        else {
            if(N/i - 1 <= i) break;
            ans += (N/i - 1);
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int,int>
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt", "w", stdout);
    // #endif
  int n; cin>>n;
  vector<int> ans(3,0);
  for(int i=0;i<n;i++){
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    vector<int> temp(3,0);

    for(int j=0;j<3;j++)
      for(int k=0;k<3;k++){
        if(j==k)continue;
        temp[k]=max(temp[k],ans[j]+a[k]);
      }

    ans=temp;
  }
  cout<<(*max_element(all(ans)))<<"\n";
  return 0;
}

Measured memory_bytes: 256
N=int(input())

graph=[[] for i in range(N+1)]

for i in range(N-1):
	a,b,w=map(int,input().split())
	graph[a].append([b,w])
	graph[b].append([a,w])


color=[-1]*(N+1)
color[1]=0

ne=[1]

while ne!=[]:
	t=ne.pop()
	for s,w in graph[t]:
		if color[s]==-1:
			ne.append(s)
			color[s]=color[t] if w%2==0 else (color[t]+1)%2

print(*color[1:],sep='\n')


Measured memory_bytes: 46648
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DEBUG_OUTPUT_ENABLED 1
	#define DBG(X) dout << #X << "=" << (X) << '\n';
	#define SAY(X) dout << (X) << '\n';
#else
	#define DEBUG_OUTPUT_ENABLED 0
	#define DBG(X) 42;
	#define SAY(X) 42;
#endif

#define dout   debug::instance

using namespace std;

template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
namespace debug {
	struct DebugStream {
		private:
			bool is_first;
		public:
			DebugStream(bool _is_first): is_first(_is_first) {}
			template<typename T> DebugStream operator<<(const T& value) const {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				cout << value;
				return DebugStream(false);
			};

			template<typename T> DebugStream printArray(T* l, T* r) {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				while(l != r) {
					cout << (*l);
					++l;
					if(l == r) {
						cout << '\n';
					} else {
						cout << ' ';
					}
				}
				return DebugStream(false);
			}
	};
	DebugStream instance(true);
};

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	int n = fetch<int>();
	int m = fetch<int>();
	auto a = fetch_vec<ll>(n);
	int cnt = 0;
	ll sum = 0;
	for(auto& x: a) sum += x;
	for(auto& x: a) {
		cnt += (x * 4 * m >= sum);
	}
	cout << (cnt >= m ? "Yes\n" : "No\n");
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
int main()
{
    ll n;
    ll k;
    std::vector<ll> A;

    std::cin >> n >> k;
    for (ll i = 0; i < n; ++i) {
        ll temp = 0;
        std::cin >> temp;
        A.push_back(temp);
    }

    for (ll i = k; i < n; ++i) {
        if (A[i] > A[i - k]) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << "No" << std::endl;
        }
    }
}

Measured memory_bytes: 5364
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; typedef long double ld;
const int INF32 = 1e9+10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  int p[20];
  for (int i = 0; i< N; i++)
    cin >> p[i];
  sort(p, p+N);
  int ans = accumulate(p, p+N-1, 0);
  ans += p[N-1]/2;
  cout << ans << endl;
}


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

int main(){
    int a=0,b,c;
    
    string s;
    cin >> s;
    for(int i=0;i<s.size()/2;i++){
        if(s.at(i)!=s.at(s.size()-i-1))
        a++;
    }
    cout << a << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <sstream>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define ios     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll mod=1000000007;
ll INF=1e18;
ll gcd (ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll fastexp(ll x ,ll n)
{
    ll result =1;
    while(n>0)
    {
        if(n%2==1)
            result*=x;
        x*=x;
        n=n/2;
    }
    return result;
}

ll modularExp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=((x%mod)*(x%mod))%mod;
        n=n/2;
    }
    return (result)%mod;
}
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
bool mycomp(pll &a,pll &b)
{
    if(a.F!=b.F)
        return a.F < b.F;
    else
        return a.S < b.S;
}

void solve()
{
     ll d,t,s;
     cin>>d>>t>>s;
     ll x = d/s;
     if(x<t)
     {
          cout<<"Yes\n";
     }
     else if(x==t)
     {
          if(d%s==0)
               cout<<"Yes\n";
          else 
               cout<<"No\n";
     }
     else 
          cout<<"No\n";
     
     
}

     
     


int main()
{
    ios;
    ll t;
//    cin>>t;
     t=1;
     while(t--)
     {
          solve();
     }
}

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

using namespace std;
using ll = long long;

#define rep(countName, left, right, up) for (ll countName = left; countName < right; countName += up)
#define rev(countName, right, left, down) for (ll countName = right - 1; countName >= left; countName -= down)

auto solve1(void)
{
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x)
    {
        return "Yes";
    }
    else
    {
        return "No";
    }
}

int main(void)
{
    cout << solve1() << endl;
    return 0;
}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main(){
    int h, w;
    cin >> h >> w;
    rep(i,w+2) cout << '#'; cout << endl;
    rep(i,h){
        string s;
        cin >> s;
        cout << '#' << s << '#' << endl;
    }
    rep(i,w+2) cout << '#'; cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#define SC unsigned long long
#define ID int
#define PP pair<SC,ID> // セクタ数、識別子
#define P pair<SC,PP > // セクタ開始、セクタ数、識別子
#define DEBUG false
using namespace std;

P makeP(SC s,SC n,ID id){ return P( s,PP(n,id) ); }

int main(){
  int n;
  char cmd;
  SC sc, inf = (SC)(1<<31) * (SC)(1<<20);;
  ID id;
  vector<P> v; // 使用中
  priority_queue< P,vector<P>, greater<P> > q; // 空き領域

  while( cin>>n && n ){
    v.clear();
    while( !q.empty() ) q.pop();
    q.push( makeP(0,inf,-1) );

    //    cout << "N=" << n << "*************" << endl;    
    while( n-- ){
      cin >> cmd;
      if( DEBUG ){
      cout << " CMD="<< cmd << " vlen="<<v.size()
	   << " qlen="<<q.size() << endl;
      for( unsigned int i=0;i<v.size();i++ )
	cout << "  "<< v[i].first << " " << v[i].second.first
	     << " |" << v[i].second.second << endl;
      cout << "  q.f " << q.top().first 
	   << " q.sf "<< q.top().second.first << endl;
    }
      switch( cmd ){
      case 'W':
	cin >> id >> sc;
	while( sc>0 ){
	  P p=q.top(); q.pop();
	  SC bgn = p.first, len = p.second.first;
	  if( sc<len ){
	    v.push_back( makeP(bgn,sc,id) );
	    q.push( makeP(bgn+sc,len-sc,-1) );
	    sc=0;
	  }else{
	    v.push_back( makeP(bgn,len,id) );
	    sc -= len;
	  }
	}
	break;
      case 'D':
	cin >> id;
	for( unsigned int i=0;i<v.size(); ){
	  if( v[i].second.second == id ){
	    q.push( v[i] );
	    v.erase( v.begin()+i );
	  }else
	    i++;
	}
	break;
      case 'R':
	cin >> sc;
	unsigned int i=0;
	while( i<v.size() ){
	  if( v[i].first <= sc && 
	      sc < v[i].first+v[i].second.first ){
	    cout << v[i].second.second << endl;
	    break;
	  }
	  i++;
	}
	if( i==v.size() )
	    cout << "-1" << endl;
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

long long MOD = 1000000007;
int sx[50];
int sy[50];
int x[50];
int y[50];
int main(){
    int n,m;
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> sx[i] >> sy[i];
    }
    for(int i=0;i<m;i++){
        cin >> x[i] >> y[i];
    }
    int p = 0;
    for(int i=0;i<n;i++){
        int shortest = ~(1 << 31);
        for(int j=0;j<m;j++){
            int len = abs(sx[i] - x[j]) + abs(sy[i] - y[j]);
            if(len < shortest){
                p = j;
                shortest = len;
            }
        }
        cout << (p+1) << endl;
    }
}


Measured memory_bytes: 256
use std::io::*;
const MOD: usize = 1_000_000_007;

fn pow(mut x: usize, mut e: usize) -> usize {
    let mut res = 1;
    while e > 0 {
        if e & 1 == 1 {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        e >>= 1;
    }
    res
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();

    let mut table: Vec<usize> = vec![0; 100010];
    let mut prime = vec![true; 100010];
    for i in 1..k + 1 {
        table[i] = pow(k / i, n);
    }

    for i in 2..k + 1 {
        if prime[i] {
            for j in 1..k / i + 1 {
                prime[i * j] = false;
                table[j] = (table[j] + MOD - table[i * j]) % MOD;
            }
        }
    }

    let mut ans = 0;
    for i in 1..k + 1 {
        ans = (ans + table[i] * i % MOD) % MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2768
n, m = map(int, input().split())
hlis = list(map(int, input().split()))
lis = [1]*n
for i in range(m):
    a, b = map(int, input().split())
    if hlis[a-1] > hlis[b-1]:
        lis[b-1] = -1
    elif hlis[a-1] < hlis[b-1]:
        lis[a-1] = -1
    elif hlis[a-1] == hlis[b-1]:
        lis[a-1] = -1
        lis[b-1] = -1
print(lis.count(1))

Measured memory_bytes: 20044
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main() {
	ll n ,m;
	cin >> n >> m;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];

	priority_queue<ll> q;
	rep(i, n)q.push(a[i]);
	
	ll x = 0;
	rep(i, m) {
		x = q.top();
		q.pop();
		x = x / 2;
		q.push(x);
	}

	ll sum = 0;
	rep(i, n) {
		sum += q.top();
		q.pop();
	}
	cout << sum << endl;
}

Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
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;}
typedef long long ll;

ll dp[2][100010];


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,W; cin >> N >> W;
    vector<int> w(N),v(N);
    REP(i,N) cin >> w[i] >> v[i];
    REP(i,N){
        REP(j,W+1){
            if(j >= w[i]) chmax(dp[(i+1)&1][j],dp[i&1][j-w[i]]+v[i]);
            chmax(dp[(i+1)&1][j],dp[i&1][j]);
        }
    }
    cout << dp[N&1][W] << endl;
    return 0;
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 2 << 60
const facNum = 300001
const INF = 2 << 60

func main() {
	sc := newScanner(os.Stdin)
	N, K, C := sc.i(), sc.i(), sc.i()
	S := sc.s()
	l := make([]int, K)
	r := make([]int, K)
	//ans := make([]int, 0)
	//for i := 0; i < N; i++ {
	//	if S[i] == 'x' {
	//		continue
	//	}
	//	s := S[0:i] + "x" + S[i+1:N]
	//	k := 0
	//	for j := 0; j < N; {
	//		if s[j] == 'x' {
	//			j++
	//			continue
	//		}
	//		k += 1
	//		j += C + 1
	//	}
	//	if k < K {
	//		ans = append(ans, i)
	//	}
	//}
	k := 0
	for i := 0; i < N; {
		if S[i] == 'x' {
			i++
			continue
		}
		l[k] = i
		k += 1
		if k >= K {
			break
		}
		i += C + 1
	}
	k = K - 1
	for i := N - 1; i >= 0; {
		if S[i] == 'x' {
			i--
			continue
		}
		r[k] = i
		k -= 1
		if k < 0 {
			break
		}
		i -= C + 1
	}
	for i := 0; i < K; i++ {
		if l[i] == r[i] {
			fmt.Println(l[i] + 1)
		}
	}
}

func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

func abs(i int) int {
	if i < 0 {
		return -i
	}
	return i
}


Measured memory_bytes: 6840
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
char a[55], b[55], c[105];
int main(){
	scanf("%s", a);
	getchar();
	scanf("%s", b);
	int ans = -1;
	int str = strlen(a);
	for(int i = 0; i < str; i++){
		c[++ans] = a[i];
		c[++ans] = b[i];
	}
	puts(c);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N, K;
    cin >> N >> K;
    int c[N];
    REP(i, N) c[i] = 0;
    REP(i, K) {
        int d;
        cin >> d;
        REP(j, d) {
            int a;
            cin >> a;
            c[a - 1]++;
        }
    }
    int ans = 0;
    REP(i, N) if (c[i] == 0) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll seki(ll l){
    ll ans = 1;
    _rep(i, 1, l + 1){
        ans *= i;
        ans %= mod;
    }
    return ans;
}
int main(){
    ll n, m; cin >> n >> m;
    if(abs(n - m) > 1)cout << 0 << endl;
    else if(n == m) cout << (2 * seki(n) * seki(n)) % mod << endl;
    else cout << seki(n) * seki(m) % mod;
}

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

int main(){
  int k; cin >>k;
  int a, b; cin >> a >> b;
  bool flag = false;
  for (int i = a; i <= b; i++)
  {
    if(i % k == 0)flag = true;
    
  }
  if(flag)cout << "OK" <<endl;
  else cout << "NG" << endl;

  return 0;
}

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

using namespace std;

pair<int, int> p[2][111111];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int v;
		scanf("%d", &v);
		p[i & 1][v].first++;
		p[i & 1][v].second = v;
	}
	for (int i = 0; i < 2; i++)
		sort(p[i], p[i] + 111111, greater<pair<int, int>>());
	if (p[0][0].second != p[1][0].second) {
		cout << n - p[0][0].first - p[1][0].first << endl;
		return 0;
	}
	cout << n - p[0][0].first - max(p[0][1].first, p[1][1].first) << endl;
	return 0;
}


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

using namespace std;

class Dice{

private:

  int top,front,right,left,back,bottom;

public:

  Dice(){
    top=1;
    front=5;
    right=4;
    left=3;
    back=2;
    bottom=6;
  }


  int North(void){
    int t;
    t=top,top=front,front=bottom,bottom=back,back=t;
    return top;
  }

  int East(void){
    int t;
    t=top,top=left,left=bottom,bottom=right,right=t;
    return top;
  }

  int West(void){
    int t;
    t=top,top=right,right=bottom,bottom=left,left=t;
    return top;
  }

  int South(void){
    int t;
    t=top,top=back,back=bottom,bottom=front,front=t;
    return top;
  }

  int Right(void){
    int t;
    t=front,front=right,right=back,back=left,left=t;
    return top;
  }

  int Left(void){
    int t;
    t=front,front=left,left=back,back=right,right=t;
    return top;
  }

  int getTop(void){
    return top;
  }

};


int main(void){
  int n;
  string s;

  while(cin >> n,n){

    Dice *d = new Dice();

    for(int i=0;i<n;i++){
      cin >>s;
      if(s=="north")d->North();
      else if(s=="east")d->East();
      else if(s=="south")d->South();
      else if(s=="west")d->West();
    }
    cout <<  d->getTop() << endl;
  }

  return 0;
}

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

int n, k, h[100110], a[100110];

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(int i=0; i<n; ++i) cin >> h[i];
	for(int i=1; i<n; ++i) a[i] = 1e9+7;
	for(int i=0; i<n; ++i)
		for(int j=1; j<=k; ++j)
			a[i+j] = min(a[i+j], a[i] + abs(h[i] - h[i+j]));
	cout << a[n-1] << "\n";
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[62][62];
void make(){
    dp[0][0]=1;
    for(int i=1;i<52;i++){
        dp[i][0]=dp[i-1][0];
        for(int j=1;j<=i;j++){
            dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
        }
    }
}
int main(){
    make();
  ll n,a,b;
  cin>>n>>a>>b;
  V<ll> d(n);
  for(int i=0;i<n;i++)cin>>d[i];
  sort(all(d),greater<ll>());
  ll sum=0;
  for(int i=0;i<a;i++)sum+=d[i];
  cout<<double(sum)/double(a)<<"\n";
  ll c=d[0],cnt=0,rem=a;
  ll t=a;
  for(int i=0;i<n;i++){
      if(d[i]==c){
          cnt++;
          a--;
      }else{
          if(a<=0)break;
          rem=a;
          cnt=1;
          c=d[i];
          a--;
      }
  }
  ll ans=0;
  if(rem==t){
  for(int i=rem;i<=min(cnt,b);i++){
      ans+=dp[cnt][i];
      //cout<<ans<<"\n";
     }
  }else ans=dp[cnt][rem];
  cout<<ans<<"\n";
}

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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	int n; cin >> n;
	vector<vector<int> > m(n, vector<int>(n));
	for(int i = 0; i < n*(n-1)/2; i++){
		int a,b,c,d; cin >> a >> b >> c >> d;
		a--;b--;
		m[a][b] = c;
		m[b][a] = d;
	}
	vector<pair<int, int> > l(n);
	for(int i = 0; i < n; i++){
		l[i] = {0,i};
		for(int j = 0; j < n; j++){
			if(m[i][j] > m[j][i])l[i].first += 3;
			else if(m[i][j] == m[j][i])l[i].first++;
		}
	}
	sort(ALL(l),greater<pair<int, int> >());
	vector<int> a(n);
	a[l[0].second] = 1;
	int cnt = 1;
	for(int i = 1; i < n; i++){
		if(l[i-1].first == l[i].first){
			a[l[i].second] = cnt;
		}
		else{
			a[l[i].second] = i+1;
			cnt = i+1;
		}


	}
	for(auto e : a)cout << e << endl;
	


	return 0;
}





Measured memory_bytes: 3128
def main():
    N , K = map(int, input().split())

    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))

    A_list.sort()
    #print(A_list)
    ans = 0
    for i in range(0,K) :
        ans = ans + A_list[i]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[][] array = new int[n][2];
		
		for(int i = 0; i < n; i++){
		    array[i][0] = i + 1;
		    array[i][1] = sc.nextInt();
		}
		Arrays.sort(array, (a, b) -> Integer.compare(a[1], b[1]));

		// 出力
		for(int i = 0; i < n; i++){
		    System.out.print(array[i][0] + " ");
		}
        
	}
}


Measured memory_bytes: 66440
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    long long N,K,S; cin >> N >> K >> S;
    if(S==pow(10,9)){
        for(int i=0;i<N;i++){
            if(i<K) cout << S <<' ';
            else cout << 1 << ' ';
        }
    }else {
        for(int i=0;i<N;i++){
            if(i<K) cout << S <<' ';
            else cout << S+1 << ' ';
        }
    }
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
int main(){
    ll no_of_weigths,tot_weight;
    cin>>no_of_weigths;
    cin>>tot_weight;
    
    ll weight[no_of_weigths],value[no_of_weigths];
    ll Sack[no_of_weigths+1][tot_weight+1];
    for(ll i=1;i<=no_of_weigths;i++){
        cin>>weight[i]>>value[i];
        Sack[i][0]=0;

        
    }
    Sack[0][0]=0;
    for(ll i=0;i<tot_weight+1;i++){
        Sack[0][i]=0;
    }
    
    for(ll i=1;i<no_of_weigths+1;i++){
        for(ll j=1;j<tot_weight+1;j++){
            
            if(j<weight[i]){
                Sack[i][j]=Sack[i-1][j];
            }
            else{
                Sack[i][j]=max(value[i]+Sack[i-1][j-weight[i]], Sack[i-1][j]);
            }
        
        }
     
    }
    
    cout<<Sack[no_of_weigths][tot_weight]<<endl;


}

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

int main(){
	int l, r;
	scanf("%d%d", &l, &r);
	
	int ser=2019;
	int agr, boon, cannon;
	if(r-l>2019) printf("0");
	else{
	for(int i=l; i<=r-1; i++){
		for(int j=i+1; j<=r; j++){
			agr = i%2019;
			boon = j%2019;
			cannon = (agr*boon)%2019;
			if(ser>cannon) ser = cannon;
		}
	}
	
	printf("%d", ser);
	}
	
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int HP,damage;
	scanf("%d %d", &HP, &damage);
	if((HP%damage==0)&&(HP>damage)) printf("%d\n", HP/damage);
	else if((HP%damage!=0)&&(HP>damage)) printf("%d\n", HP/damage+1);
	else if(HP<=damage) printf("1\n");
	return 0;
}

Measured memory_bytes: 1704
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))

    B = [0, 0, 0]
    T = [0]*N
    for i in range(N):
        # print(B)
        m = -1
        for j in range(3):
            if A[i]==B[j]:
                T[i] += 1
                m = j
        if m != -1:
            B[m] += 1
    # print(T)

    ans = reduce(lambda x,y: x*y % 1000000007, T)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 79244
#include<bits/stdc++.h>
using namespace std;
int main()
{
   map <int,int> freq;
   for(int i = 0; i < 3;i++)
   {
     int value = 0;
     cin>>value;
     freq[value]++;
   }

      if(freq[5] == 2 && freq[7] == 1)
        cout<<"YES"<<endl;
      else
        cout<<"NO"<<endl;

}


Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		List<Integer> list = new ArrayList<>();
		int answer = 0;

		Scanner scanner = new Scanner(System.in);

		int s = scanner.nextInt();
		list.add(s);

		while(true) {
			if(s%2 == 0) {
				s = s/2;
			}
			else {
				s = 3*s + 1;
			}
			answer = search(s, list);
			if(answer != 0) {
				break;
			}
			list.add(Integer.valueOf(s));
		}
		System.out.println(answer);
	}

	public static int search(int n, List<Integer> list) {

		for(int i = 0; i < list.size(); i++) {
			if(list.get(i) == n) {
				return list.size() + 1;
			}
		}
		return 0;
	}

}

Measured memory_bytes: 22736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		char[] str = cin.next().ToCharArray();
		int K = cin.nextInt();
		int res = 0;
		char c;
		for (int i = 0; i < str.Length; i++)
		{
			c = str[i];
			res = 'z' - c + 1;
			if (res != 26 && res <= K)
			{
				K -= res;
				str[i] = 'a';
			}
		}
		str[str.Length - 1] = (char)(str[str.Length - 1] + (K % 26));
		
		Console.WriteLine(new string(str));
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 4184
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 499;

int main() {
  int n;
  cin >> n;
  int num[MAX] = {};
  for (int i = 1; i < MAX; i++) {
    bool b = 1, flag = true;
    rep(j, MAX) {
      if (!num[j]) {
        if (b)
          num[j] = i;
        b ^= 1;
        flag = false;
      }
    }
    if (flag)
      break;
  }
  rep(i, n-1) rep(j, n-i-1)
    printf("%d%c", num[j], j<n-i-2?' ':'\n');
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int head=0,tail=0;
	string cmp="AKIHABARA";
	string get;
	cin>>get;
	while(head<9)
	{
		if(cmp[head]!=get[tail]&&cmp[head]=='A')
			head++;
		else if(cmp[head]!=get[tail]&&cmp[head]!='A')
		{
			cout<<"NO"<<endl;
			return 0;
		}
		else
		{
			head++;
			tail++;
		}
	}
	if(tail>get.size()-1)
	    cout<<"YES"<<endl;
	else
	    cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define from1(obj) obj.begin() + 1, obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbp(p) cerr << #p << ":(" << p.first << ", " << p.second << ") "
#define dbpl(p) cerr << #p << ":(" << p.first << ", " << p.second << ")\n"
#define dbt3(t3) cerr << #t3 << ":(" << get<0>(t3) << ", " << get<1>(t3) << ", " << get<2>(t3) << ") "
#define dbt3l(t3) cerr << #t3 << ":(" << get<0>(t3) << ", " << get<1>(t3) << ", " << get<2>(t3) << ")\n"
#define dbt4(t4) cerr << #t4 << ":(" << get<0>(t4) << ", " << get<1>(t4) << ", " << get<2>(t4) << ", " << get<3>(t4) << ") "
#define dbt4l(t4) cerr << #t4 << ":(" << get<0>(t4) << ", " << get<1>(t4) << ", " << get<2>(t4) << ", " << get<3>(t4) << ")\n"
#define dbv(vec) cerr << #vec << ":{ "; for (auto e : vec) cerr << e << ", "; cerr << "}\n"
#define dbvv(vv) cerr << #vv << ":{\n"; for (auto vec : vv) { cerr << "{ "; for (auto e : vec) cerr << e << ", "; cerr << "}\n"; } cerr << "}\n"
#define dbm(map) cerr << #map << ":{ "; for (auto p : map) cerr << "(" << p.first << ", " << p.second << "), "; cerr << "}\n"
#define YN(f) cout << (f ? "YES" : "NO") << "\n"
#define Yn(f) cout << (f ? "Yes" : "No") << "\n"
#define yn(f) cout << (f ? "yes" : "no") << "\n"
using ll = long long;
using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vb = vector<bool>;
using vvi = vector<vi>; using vvl = vector<vl>; using vvb = vector<vb>;
using pii = pair<int, int>; using pil = pair<int, ll> ; using pll = pair<ll, ll>; using pli = pair<ll, int>;
using vpii = vector<pii>; using vpll = vector<pll>;
using ti3 = tuple<int, int, int>; using tl3 = tuple<ll, ll, ll>;
using ti4 = tuple<int, int, int, int>; using tl4 = tuple<ll, ll, ll, ll>;
using mii = map<int, int>; using mil = map<int, ll>; using mll = map<ll, ll>; using mli = map<ll, int>;

int main() {
	int N; cin >> N;
	string A, B, C; cin >> A >> B >> C;
	int ans = 0;
	rep(i, N) {
		if (A[i] != B[i] && B[i] != C[i] && C[i] != A[i]) ans += 2;
		else if (A[i] == B[i] && B[i] == C[i] && C[i] == A[i]) {}
		else ans ++;
	}
	cout << ans << endl;	
}

Measured memory_bytes: 256
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

a = b = None

for i, x in enumerate(itertools.permutations(range(1, n+1), n)):
	if p == x:
		a = i
		if b:
			break
		
	if q == x:
		b = i
		if a:
			break
			
print(abs(a - b))


Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

int main(){
  int n;
  cin >> n;
  int mi = 1000000007;
  int ans = 0;
  for(int i=0;i<n;i++){
    int p;
    cin >> p;
    if(p<=mi) ans++;
    mi = min(mi,p);
  }
  cout<< ans <<endl;

}


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

using namespace std;

int const N = 1234;

long long f[N];
int c[N][4];
long long dp[42];
int can[42];
long long cr[N][4];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      scanf("%d", c[i] + j);
    }
    for (int rot = 0; rot < 4; rot++) {
      long long z = 0;
      for (int e = 0; e < 4; e++) {
        z = z * 1000 + c[i][(e + rot) & 3];
      }
      cr[i][rot] = z;
    }
  }
  long long ans = 0;
  for (int first = 0; first < n; first++) {
    for (int back = first + 1; back < n; back++) {
      for (int rb = 0; rb < 4; rb++) {
        for (int i = 0; i < 4; i++) {
          f[i] = c[first][(i + 1) & 3];
          f[i] = f[i] * 1000 + c[first][i];
          f[i] = f[i] * 1000 + c[back][(-i + rb + 1) & 3];
          f[i] = f[i] * 1000 + c[back][(-i + rb) & 3];
        }
        for (int i = 0; i < 1 << 4; i++) dp[i] = 0;
        dp[0] = 1;
        for (int i = first + 1; i < n; i++) {
          if (i == back) continue;
          for (int j = 0; j < 4; j++) {
            can[j] = 0;
            for (int rot = 0; rot < 4; rot++) {
              if (f[j] == cr[i][rot]) {
                ++can[j];
              }
            }
          }
          // for (int mask = 15; mask >= 0; mask--) {
          //   for (int j = 0; j < 4; j++) {
          //     if (can[j] == 0 || ((mask >> j) & 1) == 0) continue;
          //     dp[mask] += dp[mask & ~(1 << j)] * can[j];
          //   }
          // }
          dp[15] += dp[14] * can[0];
          dp[15] += dp[13] * can[1];
          dp[15] += dp[11] * can[2];
          dp[15] += dp[7] * can[3];
          dp[14] += dp[12] * can[1];
          dp[14] += dp[10] * can[2];
          dp[14] += dp[6] * can[3];
          dp[13] += dp[12] * can[0];
          dp[13] += dp[9] * can[2];
          dp[13] += dp[5] * can[3];
          dp[12] += dp[8] * can[2];
          dp[12] += dp[4] * can[3];
          dp[11] += dp[10] * can[0];
          dp[11] += dp[9] * can[1];
          dp[11] += dp[3] * can[3];
          dp[10] += dp[8] * can[1];
          dp[10] += dp[2] * can[3];
          dp[9] += dp[8] * can[0];
          dp[9] += dp[1] * can[3];
          dp[8] += dp[0] * can[3];
          dp[7] += dp[6] * can[0];
          dp[7] += dp[5] * can[1];
          dp[7] += dp[3] * can[2];
          dp[6] += dp[4] * can[1];
          dp[6] += dp[2] * can[2];
          dp[5] += dp[4] * can[0];
          dp[5] += dp[1] * can[2];
          dp[4] += dp[0] * can[2];
          dp[3] += dp[2] * can[0];
          dp[3] += dp[1] * can[1];
          dp[2] += dp[0] * can[1];
          dp[1] += dp[0] * can[0];
        }
        ans += dp[15];
      }
    }
  }
  printf("%lld\n", ans);
}


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

int main() {
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(), v.end());
    int ans = 0;
    ans += abs(v[0] - v[1]);
    ans += abs(v[1] - v[2]);
    cout << ans << endl;
}

Measured memory_bytes: 1016
/* ex5_4
   hangan2020*/ 

#include <stdio.h>
#include <string.h>

int main(void){
    char str[11],  *p; 
    int len, max;

    //文字列入力
    scanf("%s", &str[0]);
    //文字列先頭のアドレス
    p = str;
    len = 0;
    max = 0; 

    //null文字ではない間に
    while(*p){
        
        //長さリセット
        len = 0;

        //ACGT列を見つけたら長さをカウントする。
        //カウントが終わるとポインタは最後の文字の次の文字にある
        while(*p == 'A'||*p == 'C'||*p == 'G'||*p == 'T'){
            len++;
            p++;
        }
        
        //もしカウントしている文字列が最長の文字列より長かったらmaxにする
        if(len > max){
            max = len;
        }

        //次の文字へ
        p++;

    }

    printf("%d", max);

    return 0;

}


Measured memory_bytes: 1708
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  int n;
  cin >> n;

  int l, r, res;
  res = 0;

  FOR(i, 0, n){
    cin >> l >> r;
    res += r-l+1;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())

count = 0

while a >= b:
    if a >= b:
        b *= 2
        count +=1

while b >= c:
    if b >= c:
        c *= 2
        count += 1
        continue
#print(count,a,b,c)

if count <= k:
    print("Yes")
else:
    print("No")

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

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

  if (a < b)
  {
    cout << "a < b" << endl;
  }
  else if (a > b)
  {
    cout << "a > b" << endl;
  }
  else
  {
    cout << "a == b" << endl;
  }  
}


Measured memory_bytes: 3104
n = int(input())
a = list(map(int,input().split()))
ans = 1
length = 1
k = 0
for i in range(1,n):
    if k==0:
        if a[i]>a[i-1]:
            k = 2
        elif a[i]<a[i-1]:
            k = 1
        else:
            continue
    if k==2 and a[i]>=a[i-1] or k==1 and a[i]<=a[i-1]:
        continue
    k = 0
    ans += 1
print(ans)

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,b=1,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a==b){
			cnt++;
			b++;
		}
	}
	if(b==1){
		cout<<-1<<endl;
	}else{
		cout<<n-cnt<<endl;
	}
	return 0;
}


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

int main()
{
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    for(int N; std::cin >> N; )
    {
        typedef long long T;
        std::vector<std::pair<T,T>> ab(N);
        for(auto&v:ab) std::cin >> v.first >> v.second;
        T c=0;
        for(int i=N-1; i>=0; --i) {
            const auto a=ab[i].first,b=ab[i].second;
            c+=(b-(a+c)%b)%b;
        }
        std::cout << c << std::endl;
    }
}

Measured memory_bytes: 1920
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

vector<int> G[100000];
bool vis[100000];
vector<int> ord;

void visit(int n){
	if(!vis[n]){
		vis[n] = true;
		for(int i = 0; i < G[n].size(); i++){
			visit(G[n][i]);
		}
		ord.push_back(n);
		//cout << n;
	}
}

int main(){
	
	int V, E;
	cin >> V >> E;
	
	for(int i = 0; i < E; i++){
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		G[x].push_back(y);
	}
	
	for(int i = 0; i < V; i++){
		visit(i);
	}
	
	reverse(ord.begin(), ord.end());
	
	for(int i = 0; i < ord.size(); i++){
		cout << ord[i] + 1 << endl;
	}
	
	bool flag = true;
	
	for(int i = 0; i < ord.size() - 1; i++){
		bool exist = false;
		for(int j = 0; j < G[ord[i]].size(); j++){
			if(G[ord[i]][j] == ord[i + 1]){
				exist = true;
			}
		}
		flag = (flag && exist);
	}
	
	cout << !flag << endl;
	
	return 0;
}


Measured memory_bytes: 6000
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始
int main(){
  int n;
  cin>>n;
  int a[n],b[n];
  vector<pair<pair<ll,int>,int> > v;
  for(int i = 0; i < n; i++){
    cin>>a[i]>>b[i];
    ll x = a[i] + b[i];
    v.push_back(make_pair(make_pair(x,a[i]),b[i]));
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  ll takashi = 0;
  ll aoki = 0;
  for(int i = 0; i < n; i++){
    if(i%2==0){
      takashi+=v[i].first.second;
    }
    else{
      aoki+=v[i].second;
    }
  }
  cout<<takashi-aoki<<endl;
  return 0;
}



Measured memory_bytes: 5492
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
ai,aj=[],[]
for i in range(n):
  aj.append(i-a[i])
  ai.append(i+a[i])
c1=Counter(ai)
c2=Counter(aj)
ans=0
for k in c1.keys():
  ans+=c1[k]*c2[k]
print(ans)




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

int main() {
    long long n;
    cin >> n;
    int ans = 1e9+1;
    for(long long i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            string s1 = to_string(i), s2 = to_string(n/i);
            ans = min(ans, (int)max(s1.size(), s2.size()));
        }
    }

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

Measured memory_bytes: 256
candidates = {i for i in range(-1, 102)}
X, N = map(int, input().split())
P = set(map(int, input().split()))
diff = float('inf')
ans = -100
for x in candidates - P:
    if abs(x - X) < diff:
        diff = abs(x - X)
        ans = x
print(ans)

Measured memory_bytes: 9192
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iterator>
#include <functional>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define sz(a)  int((a).size())
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define CLR(a) memset((a), 0, sizeof(a))
#define INF (1 << 31) - 1
const int dh[8] = {-1, 1, 0, 0,1,1,-1,-1};
const int dw[8] = {0, 0, 1, -1,1,-1,1,-1};
typedef long long ll;
typedef pair<int, int> p;
typedef vector <int> VI;
typedef vector <string> VS;

vector <int> his;

int main(){

	int n,k;
	cin >> n;
	cin >> k;
	
	ll bests = 0;
	ll diffs = 0;
	vector <ll> a(n);
	vector <ll> best(n);
	vector <ll> diff(n);	
	ll ans = 0;

	for(int i = 0; i < n; i++){
		int num;
		cin >> num;
		
		a[i] = num;
		if(num > 0) ans += num;

		if(i < k){
			if(num > 0){
				bests += num;				
			}
			best[i] = bests;			
			diffs += num;
			diff[i] = diffs;
		}else{
			if(a[i - k] > 0){
				bests -= a[i-k];
			}
			if(num > 0){
				bests += num;
			}
			best[i] = bests;											
			diffs += (num - a[i-k]);
			diff[i] = diffs;			
		}
	}

	ll mindiff = 9223372036854775807;
	for(int i = k-1; i < n; i++){
		mindiff = min(mindiff, min(best[i], best[i] - diff[i]));		
	}
	cout << ans - mindiff << endl;
	return 0;	
}


Measured memory_bytes: 2560
#include<stdio.h>
int main(){
  int n,m,i,j,l,a,b,o,h,min,mi;
  int d[30][30],f[30][2],c[30][2],s[2];
  scanf("%d %d",&n,&m);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++)d[i][j]=100000000;
    c[i][0]=c[i][1]=100000000;
    f[i][0]=f[i][1]=0;
  }
  while(m--){
    scanf("%d,%d,%d,%d",&a,&b,&o,&h);
    d[a][b]=o;
    d[b][a]=h;
  }
  scanf("%d,%d,%d,%d",&s[0],&s[1],&h,&o);
  h-=o;
  for(l=0;l<2;l++){
    c[mi=s[l]][l]=0;
    for(i=0;i<n;i++){
      f[mi][l]=1;
      for(j=1;j<=n;j++){
	if(f[j][l])continue;
	if(c[j][l]>c[mi][l]+d[mi][j])c[j][l]=c[mi][l]+d[mi][j];
      }
      min=2100000000;
      for(j=1;j<=n;j++){//printf("%d ",c[j][l]);
	if(f[j][l])continue;
	if(min>c[j][l])min=c[mi=j][l];
      }//printf("\n");
    }//printf("\n");
    h-=c[s[1-l]][l];
  }
  printf("%d\n",h);
  return 0;
}

Measured memory_bytes: 600
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

long long int getGcd(long long int m, long long int n) {
	if (n == 0) return m;
	return getGcd(n, m % n);
}

int main() {
	long long int n, m;
	cin >> n >> m;
	long long int a[100000];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long int twonum = 0;
	while (a[0] % 2 == 0) {
		twonum++;
		a[0] /= 2;
	}
	bool ok = true;
	for (int i = 1; i < n; i++) {
		long long int tmp = 0;
		while (a[i] % 2 == 0) {
			tmp++;
			a[i] /= 2;
		}
		if (tmp != twonum) {
			ok = false;
			break;
		}
	}
	if (ok) {
		long long int gcd = a[0];
		long long int tmp = a[0];
		for (int i = 1; i < n; i++) {
			gcd = getGcd(tmp, a[i]);
			tmp = (tmp * a[i]) / gcd;
		}
		tmp *= (1 << (twonum - 1));
		// cout << tmp << endl;
		cout << (m / tmp) / 2 + (m / tmp) % 2 << endl;
	} else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 1024
n = int(input())

resultMax = 0
resultI = 0
for i in range(n,0,-1) :
  result = 0
  t = i
  while t%2 == 0:
    t = t//2
    if t == 1 and result+1 >= resultMax:
      print(i)
      exit(0) 
    result += 1
  if resultMax <= result:
    resultMax = result
    resultI = i

print(resultI)


Measured memory_bytes: 3060