akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

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

  int ans = 0, tmp = 0;

  //0101...
  REP(i, n){
    if(i%2){
      if(s[i] != '1') ans++;
    }
    else{
      if(s[i] != '0') ans++;
    }
  }
  
  //1010...
  REP(i, n){
    if(i%2){
      if(s[i] != '0') tmp++;
    }
    else{
      if(s[i] != '1') tmp++;
    }
  }
  cout << min(ans, tmp) << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

ll dp[3001][3001];

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    dp[0][0]=1;
    for(int i=0;i<n-1;i++){
        for(int j=0;j<=i;j++){
            if(s[i]=='>'){
                dp[i+1][0]+=dp[i][j];
                dp[i+1][j+1]-=dp[i][j];
            }
            else{
                dp[i+1][j+1]+=dp[i][j];
                dp[i+1][i+2]-=dp[i][j];
            }
        }
        dp[i+1][0]%=MOD;
        for(int j=1;j<n;j++){
            dp[i+1][j]=(dp[i+1][j]+dp[i+1][j-1])%MOD;
        }
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=dp[n-1][i];
    }
    ans%=MOD;
    ans=(ans+MOD)%MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 70528
#include <iostream>
#include <set>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>
typedef long long ll;

using namespace std;

signed main(){
  int n;
  cin >> n;
  cout << n * n << endl;
}


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

int main() {
	int N;
	cin >> N;
	int t = N;
	int c = 0;
	while (t > 0){
		c += t % 10;
		t /= 10;
	}
	if (N % c == 0){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

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


int main(){
  int N;
  cin >> N;
  int cnt_2 = 0;
  int cnt_4 = 0;
  int cnt_other = 0;
  REP(i,N){
    ll a;
    cin >> a;
    if(a%4==0){
      cnt_4++;
    }else if(a%2==0){
      cnt_2++;
    }else{
      cnt_other++;
    }

  }

  if(cnt_2==0){
    if(cnt_4+1>=cnt_other){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    if(cnt_4>=cnt_other){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}



Measured memory_bytes: 256
from fractions import gcd
n = int(input())
ns = list(map(int, input().split()))
l = [0]
r = [0]
for i in range(n-1):
    l += [gcd(l[i], ns[i])]
    r += [gcd(r[i], ns[-i-1])]
print(max(gcd(l[i], r[-i-1]) for i in range(n)))

Measured memory_bytes: 16068
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
const int N=2007;
int n,A[N];
int main() {
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&A[i]); 
	sort(A+1,A+1+n);
	long long ans=0;
	For(i,1,n)
		For(j,i+1,n) {
			int k=lower_bound(A+1,A+1+n,A[i]+A[j])-A;
			ans+=max(0,k-j-1);
		}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
void __dump(int x){cerr << x;}
void __dump(long long x){cerr << x;}
void __dump(long double x){cerr << fixed << setprecision(3) << x;}
void __dump(char x){cerr << '\'' << x << '\'';}
void __dump(const string &x){cerr << '"' << x << '"';}
void __dump(const char *x){cerr << '"' << x << '"';}
void __dump(bool x){cerr << (x ? "true" : "false");}
void _dump(){cerr << "\n";}
template <typename T, typename U> void __dump(const pair<T, U> &x){cerr << '{'; __dump(x.first); cerr << ','; __dump(x.second); cerr << '}';}
template <typename T, typename U, typename V> void __dump(const tuple<T, U, V> &x){cerr << '{'; __dump(get<0>(x)); cerr << ',';  __dump(get<1>(x)); cerr << ',';  __dump(get<2>(x)); cerr << '}';}
template <typename T> void __dump(const T& x){int f=0; cerr << '{'; for(auto&i:x) cerr << (f++ ? "," : ""), __dump(i); cerr << "}";}
template <typename T, typename ... U> void _dump(T t, U ... u){__dump(t); if(sizeof...(u)) cerr << ", "; _dump(u...);}
#define dump(x ...) cerr  <<  "|| "  <<  # x  <<  "  =  ", _dump(x) 
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
#define __ ' '
#define LL long long
#define LD long double
#define pii pair<int,int>
const int INF = 2e9;
const int NN = 1e5;
int x,y,z;
int n;
int a[NN+3], b[NN+3], c[NN+3];
int p[NN+3];
priority_queue<LL, vector<LL>, greater<LL>> prefPQ, suffPQ;
LL pref[NN+3], suff[NN+3];
LL ans, sumC;

int main(){ FAST
	cin >> x >> y >> z;
	n = x + y + z;
	for(int i=1; i<=n; ++i) cin >> a[i] >> b[i] >> c[i];

	for(int i=1; i<=n; ++i){
		a[i] -= c[i];
		b[i] -= c[i];
		sumC += c[i];
	}

	for(int i=1; i<=n; ++i) p[i] = i;
	sort(p+1, p+n+1, [&](int l, int r){ return a[l]-b[l] < a[r]-b[r]; });

	for(int i=1; i<=y; ++i){
		LL cur = b[p[i]];

		prefPQ.push(cur);
		pref[i] = pref[i-1] + cur;
	}
	for(int i=y+1; i<=n; ++i){
		LL cur = b[p[i]];

		pref[i] = pref[i-1];
		pref[i] += cur;
		prefPQ.push(cur);
		pref[i] -= prefPQ.top();
		prefPQ.pop();
	}

	for(int i=n; i>=n-x+1; --i){
		LL cur = a[p[i]];

		suffPQ.push(cur);
		suff[i] = suff[i+1] + cur;
	}
	for(int i=n-x; i>=1; --i){
		LL cur = a[p[i]];

		suff[i] = suff[i+1];
		suff[i] += cur;
		suffPQ.push(cur);
		suff[i] -= suffPQ.top();
		suffPQ.pop();
	}

	for(int ind=y; ind+x<=n; ++ind) ans = max(ans, sumC + pref[ind] + suff[ind+1]);

	cout << ans << ln;
}

Measured memory_bytes: 4472
k = int(input())

if k % 2 == 0 or k % 5 == 0:
  print(-1)
else:
  ans = 7
  cnt = 1
  while 1:
    if ans % k == 0:
      break
    else:
      cnt += 1
      ans *= 10
      ans += 7
      ans %= k

  print(cnt)      

Measured memory_bytes: 9120
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int main(){
  long long n;
  cin >> n;
  long long tmp = 1;
  int ans = 0;
  while(true){
    tmp *= 3;
    ans ++;
    if(tmp >= n){
      break;
    }
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std ;

const int MAX = 300 + 10 ;

char arr[MAX][MAX] ;
int n , m , k ;
int ans[MAX][MAX] ;

int cnt = 0 ;

void mark(int x1 , int y1 , int x2 , int y2)
{
	for(int i = x1 ; i <= x2 ; ++i)
	{
		for(int j = y1 ; j <= y2 ; ++j)
			ans[i][j] = cnt ;
	}
}


int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m>>k ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 0 ; j < m ; ++j)
			cin>>arr[i][j] ;
	}
	int lasti = 0 , lastj = 0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		int cnt2 = 0 ;
		for(int j = 0 ; j < m ; ++j)
		{
			if(arr[i][j] == '#')
				cnt2++ ;
		}
		if(cnt2 == 0)
			continue ;
		for(int j = 0 ; j < m ; ++j)
		{
			if(arr[i][j] == '#')
			{
				cnt++ ;
				cnt2-- ;
				if(cnt2 == 0)
					mark(lasti , lastj , i , m-1) ;
				else
					mark(lasti , lastj , i , j) , lastj = j+1 ;
			}
		}
		lasti = i+1 ;
		lastj = 0 ;
	}
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 0 ; j < m ; ++j)
		{
			if(!ans[i][j])
				ans[i][j] = ans[i-1][j] ;
			cout<<ans[i][j]<<" " ;
		}
		cout<<"\n" ;
	}
	return 0 ;
}		

Measured memory_bytes: 4112
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CSnack {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        lint A, B;
        in>>A>>B;
        out<<A/__gcd(A, B)*B<<'\n';
    }
};


int main() {
	CSnack solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3584
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main(){
  int n,m,k;

  scanf("%d",&k);
  vector< pair<int,int> > inv(k);
  for(int i=0;i<k;i++){
    int a,b,c,d;
    scanf("%d:%d-%d:%d",&a,&b,&c,&d);
    inv[i] = make_pair(a*60+b, c*60+d);
  }

  scanf("%d",&n);
  vector< vector< pair<int,int> > > t(n);
  for(int i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    for(int j=0;j<x;j++){
      int a,b,c,d;
      scanf("%d:%d-%d:%d",&a,&b,&c,&d);
      t[i].push_back( make_pair(a*60+b, c*60+d) );
    }
  }

  scanf("%d",&m);
  vector< vector< pair<int,int> > > s(m);
  for(int i=0;i<m;i++){
    int x;
    scanf("%d",&x);
    for(int j=0;j<x;j++){
      int a,b,c,d;
      scanf("%d:%d-%d:%d",&a,&b,&c,&d);
      s[i].push_back( make_pair(a*60+b, c*60+d) );
    }
  }

  vector<int> tn(k,0), sn(k,0);

  for(int i=0;i<k;i++){
    for(int j=0;j<n;j++){
      bool f = false;
      for(pair<int,int> p : t[j]){
	if( p.first <= inv[i].first && inv[i].second <= p.second )f = true;
      }
      if(f)tn[i]++;
    }

    for(int j=0;j<m;j++){
      bool f = false;
      for(pair<int,int> p : s[j]){
	if( p.first <= inv[i].first && inv[i].second <= p.second )f = true;
      }
      if(f)sn[i]++;
    }
  }

  int ans = 0;
  for(int i=0;i<k;i++){
    ans += min(tn[i], sn[i]);
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()
 
#define pb push_back
#define ff first
#define ss second
#define hell 1000000007
 
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 300009
 
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n,a,b;
	cin>>n>>a>>b;
	
	ll times=n/(a+b);
	times*=a;
	ll mod=n%(a+b);
	if(mod>a)
	times+=a;
	else
	times+=mod;
	cout<<times<<endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {
      val n = readLine().split(" ").map(_.toInt)
      println( if(n(0) > n(1)) "a > b" else if (n(0) < n(1)) "a < b" else "a == b")
  }
}

Measured memory_bytes: 43776
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int x;
  cin >> x;
  int now = 100;
  int ans = 0;
  while(now < x){
    now *= 1.01;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    string Key = "keyence";
    string sub = s.substr(0,7);
    if(sub == Key)
    {
        cout << "YES\n";
    }
    else
    {
        sub = s.substr(s.size() - 7,7);
        if(sub == Key)
        {
            cout << "YES\n";
        }
        else
        {
            int i = 0,j = 0;
            while(true)
            {
                if(s[i] != Key[j])
                {
                    break;
                }
                i++;
                j++;
            }
            bool flag = true;
            i = s.size() - (Key.size() - j);
            while(i < s.size())
            {
                if(s[i] != Key[j])
                {
                    flag = false;
                    break;
                }
                i++;
                j++;
            }
            if(flag)
            {
                cout << "YES\n";
            }
            else
            {
                cout << "NO\n";
            }
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    char s[a+b+2];
    scanf("%s", s);
    for(int i = 0; i < a; i++){
        if(s[i] == '-') {
            puts("No");
            return 0;
        }
    }
    if (s[a] != '-') {
        puts("No");
        return 0;
    }
    for(int i = a + 1; i < a + b + 1; i++){
        if (s[i] == '-'){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}


Measured memory_bytes: 128
#include<stdio.h>

int main()
{
	int time;
	int h,m,s;
	scanf("%d",&time);
	h = time/3600;
	time -= h*3600;
	m = time/60;
	time -= m*60;
	s = time;
	
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


Measured memory_bytes: 2736
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int p[52]={0};p[0]=-100;
        for(int i=0;i<n;i++)scanf("%d",&p[i+1]);
        printf("%d",p[1]);
        for(int i=2;i<=n;i++){
            if(p[i]==p[i-1]+1&&p[i]==p[i+1]-1)continue;
            if(p[i]==p[i-1]+1)printf("-%d",p[i]);
            else printf(" %d",p[i]);
        }
        puts("");
    }

    return 0;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a.begin(), a.end());
	ll ans = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = i + 1; j < n; ++j)
		{
			if (a[i] == a[j])
				continue;
			for (int k = j + 1; k < n; k++)
			{
				if (a[j] == a[k])
					continue;
				if (a[i] + a[j] > a[k])
					ans++;
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <vector>
#include <cstdint>
#include <functional>

using namespace std;

template <class RandomIt>
struct swin_result {
    RandomIt first, last;
    typename RandomIt::value_type top;
    typename RandomIt::difference_type number, largest, smallest;
    swin_result() {}
    swin_result(typename RandomIt::value_type init):
        top(init), number(0), largest(0), smallest(0)
    {}
};

template <
    class RandomIt, class UnaryPredicate, class BinaryOperation,
    class BinaryInvOperation,
    class BinaryPredicate=less<typename RandomIt::value_type>
>
swin_result<RandomIt> slide_window(
    RandomIt first, RandomIt last, UnaryPredicate unary_p,
    BinaryOperation binary_op, BinaryInvOperation binary_invop,
    typename RandomIt::value_type e,
    BinaryPredicate binary_p=less<typename RandomIt::value_type>()
) {
    swin_result<RandomIt> res(e);
    typename RandomIt::value_type cur=e;
    typename RandomIt::difference_type len=0;
    for (RandomIt open=first, close=open; close<last; ++close) {
        cur = binary_op(cur, *close);
        while (!unary_p(cur)) {
            cur = binary_invop(cur, *open);
            ++open;
            --len;
        }
        res.number += ++len;
    }
    return res;
}

int main() {
    size_t N;
    int Q;
    scanf("%zu %d", &N, &Q);

    vector<int64_t> a(N);
    for (size_t i=0; i<N; ++i)
        scanf("%lld", &a[i]);

    auto add=[](int64_t lhs, int64_t rhs)->int64_t {
        return lhs + rhs;
    };
    auto sub=[](int64_t lhs, int64_t rhs)->int64_t {
        return lhs - rhs;
    };

    for (int i=0; i<Q; ++i) {
        int64_t x;
        scanf("%lld", &x);
        swin_result<vector<int64_t>::iterator> res=slide_window(
            a.begin(), a.end(), [x](int64_t s) {
                return s <= x;
            }, add, sub, 0
        );

        printf("%td\n", res.number);
    }
    return 0;
}

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

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

    return 0;
}

Measured memory_bytes: 256
import numpy as np

N = input().split(" ")
r = int(N[0])
D = int(N[1])
x = int(N[2])
y = []
y.append(r*x-D)
for i in range(9):
    print(y[i])
    y.append(r*y[i]-D)
print(y[len(y)-1])

Measured memory_bytes: 12396
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long k,x,mini,maxi;
  cin>>k>>x;
  mini=x-k+1;
  maxi=x+k-1;
  for(long long i=mini;i<=maxi;i++){
    cout<<i<<" ";
  }
  return 0;
}

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

int h,w;
vector<string> mp;
queue<pair<int,int>> visit;
vector<vector<int>> d;

bool ans=false;

void bfs(int i, int j){
  if(i==h-1 && j==w-1){
    ans=true;
    return;
  }else{
    vector<int> dx={0,1,0,-1};
    vector<int> dy={1,0,-1,0};

    for(int k=0; k<4; k++){
      if(0<=i+dy[k] && i+dy[k]<h && 0<=j+dx[k] && j+dx[k]<w && mp[i+dy[k]][j+dx[k]]=='.' && d[i+dy[k]][j+dx[k]]==h*w+1){
        d[i+dy[k]][j+dx[k]]=d[i][j]+1;
        visit.push(make_pair(i+dy[k],j+dx[k]));
      }
    }
  }
}

int main(){
  int black=0;
  cin>>h>>w;
  mp.resize(h);
  d=vector<vector<int>>(h, vector<int>(w,h*w+1));
  for(int i=0; i<h; i++){
    cin>>mp[i];
    for(int j=0; j<w; j++){
      if(mp[i][j]=='#')black++;
    }
  }

  visit.push(make_pair(0,0));
  d[0][0]=0;
  while(!ans && !visit.empty()){
    pair<int,int> x=visit.front();
    visit.pop();
    bfs(x.first, x.second);
  }

  if(ans)cout<<h*w-black-d[h-1][w-1]-1<<endl;
  else cout<<-1<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
    int cnt[100005];
    long long sum=0;
int main(void)
{
    int n;
    cin>>n;
    int i;
    for(i=0;i<n;i++)
    {
        int in;
        cin>>in;
        if(in>n)
            sum++;
        else
            cnt[in]++;
    }
    for(i=0;i<=n;i++)
    {
        if(cnt[i]==0||cnt[i]==i)
            continue;
        if(cnt[i]>i)
            sum+=cnt[i]-i;
        else
            sum+=cnt[i];
    }
    cout<<sum<<endl;
    return 0;
}




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

int main(){
    string str;
    cin >> str;
    for(int i = 0; i < str.length()/2; i++){
        if(str[i] != str[str.length() - i - 1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///


int main(){

    int n;
    I(n);
    ll ar[n+2];
    ll sum = 0;
    ll ma = 0;
    for(int i = 1;i<=n;i++){
        L(ar[i]);
        sum += ar[i];
        ma = max(ma,ar[i]);
    }

    cout<<(sum -ma/2)<<endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    Scanner sc = new Scanner(System.in);

    static class Tree{
    	Tree left;
    	Tree right;
    	Tree(){
    	}
    	Tree(String s){
    		int bc=0;
    		int i=0;
    		for(;i<s.length();i++){
    			if(s.charAt(i)=='(')bc++;
    			if(s.charAt(i)==')')bc--;
    			if(s.charAt(i)==',' && bc==1){
    				if(i>1){
    					left=new Tree(s.substring(1,i));
    				}
    				if(i+1<s.length()-1){
    					right=new Tree(s.substring(i+1,s.length()-1));
    				}
    				return;
    			}
    		}
    	}
    	public static Tree Intersect(Tree a,Tree b){
    		if(a!=null && b!=null){
    			Tree tree=new Tree();
    			if(a.left!=null && b.left!=null){
	    			tree.left=Intersect(a.left,b.left);
	    		}
	    		if(a.right!=null && b.right!=null){
	    			tree.right=Intersect(a.right,b.right);
	    		}
	    		return tree;
    		}
    		return null;
    	}
    	public static Tree Union(Tree a,Tree b){
    		if(a==null && b==null){
    			return null;
    		}
    		Tree tree=new Tree();
    		if((a!=null && a.left!=null) || (b!=null && b.left!=null)){
    			tree.left=Union(a!=null?a.left:null,b!=null?b.left:null);
    		}
    		if((a!=null && a.right!=null) || (b!=null && b.right!=null)){
    			tree.right=Union(a!=null?a.right:null,b!=null?b.right:null);
    		}
    		return tree;
    	}


    	public String toString(){
    		return "("+(left!=null?left:"")+","+(right!=null?right:"")+")";
    	}
    }

    public void run() {
        while(sc.hasNext()){
        	String key=sc.next(),a=sc.next(),b=sc.next();
        	Tree ta=new Tree(a);
        	Tree tb=new Tree(b);
        	if("i".equals(key)){
        		ln(Tree.Intersect(ta, tb));
        	}else if("u".equals(key)){
        		ln(Tree.Union(ta, tb));
        	}else{
        	}
        }
    }
    public static void main(String[] args) {
        new Main().run();
    }
    public static void pr(Object o) {
        System.out.print(o);
    }
    public static void ln(Object o) {
        System.out.println(o);
    }
    public static void ln() {
        System.out.println();
    }
}

Measured memory_bytes: 12000
days = int(input())
yen = 1000
prices = list(map(int, input().split()))
stocks = 0

for i in range(0, days-1):
  if prices[i] < prices[i+1]:
    stocks += yen // prices[i]
    yen %= prices[i]
  elif prices[i] > prices[i+1]:
    yen += stocks*prices[i]
    stocks = 0


yen += stocks*prices[days-1]

print(yen)


Measured memory_bytes: 9032
#include <stdio.h>

int main(void){
	int n, x = 0, max = 0;
	char c;
	scanf("%d\n", &n);
	for(int i = 0; i < n; i++){
		scanf("%c", &c);
		if(c == 'I')x++;
		else x--;
		if(x > max)max = x;
	}
	printf("%d\n", max);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    ll X, Y;
    cin >> X >> Y;
    ld tmp = (Y-2.0*X)/2.0;
    if (floor(tmp) == tmp&& 0 <= tmp&&0<=(X-tmp)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
/*_47*/
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define pll pair<ll,ll>
#define pk pair<pll,ll>
#define endl "\n"
#define si(x) (ll)((x).size())
#define pb push_back
#define F first
#define S second
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>=1;i--)
#define all(x) (x).begin(), (x).end()
#define pr_vec(v) for(auto __:v) cout<<__<<" ";
#define make_unique(x) (x).resize(unique(all(x))-(x).begin())
const int N = 1e6 + 5;
void solve()
{
    ll n, m;
    cin>>n>>m;
    ll ans=n-n/m*m;
    cout<<min(ans,m-ans);
}

int main()
{



    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    rep1(i, t)
    {
        // cout << "Case #" << i << ": ";
        solve();
        // cout << endl;
    }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 2*1e9;

int main(){
  int n;
  cin>>n;
  vector<vector<int>> A(n,vector<int>(3,0));
  int a,b,c;
  for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      A[i] = {a,b,c};
  }
  
  vector<vector<int>> dp(n,vector<int>(3,0));
  for(int i=0;i<3;i++){
      dp[0][i] = A[0][i];
  }
  
  for(int i=1;i<n;i++){
      int elem=0;
      for(int j=0;j<3;j++){
          elem=0;
          for(int k=0;k<3;k++){
              if(k!=j)
                elem=max(elem,A[i-1][k]);
          }
          //cout<<"elem: "<<elem<<endl;
          A[i][j]+=elem;
      }
  }
//   for(int i=0;i<n;i++){
//       for(int j=0;j<3;j++){
//           cout<<A[i][j]<<" ";
//       }
//       cout<<endl;
//   }
//   cout<<endl;
  int ans=0;
  for(int j=0;j<3;j++){
      ans = max(ans,A[n-1][j]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 11136
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
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;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

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


    ll xa = 0;
    if((a - 1) % 4 == 0){
        xa = a - 1;
    } else if((a - 1) % 4 == 1){
        xa = 1;
    } else if((a - 1) % 4 == 2){
        xa = a;
    } else {
        xa = 0;
    }

    ll xb = 0;
    if(b % 4 == 0){
        xb = b;
    } else if(b % 4 == 1){
        xb = 1;
    } else if(b % 4 == 2){
        xb = b + 1;
    } else {
        xb = 0;
    }

    cout << (xa ^ xb) << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
   int t,a[100],j,i,sum=0;
   scanf("%d", &t);
   for(i=0;i<t;i++)
   {
       scanf("%d", &a[i]);
   }
    for(i=0;i<t;i++)
   {
       for(j=i+1;j<t;j++)
       {
           sum=sum+a[i]*a[j];
       }
   }
   printf("%d\n", sum);

     return 0;
 }


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    ll n;cin>>n;
    string ans="";
    if(n==0)ans="0";
     while(n){
         if(n%(-2)!=0)ans+='1',n--;
         else ans+='0';
         n/=-2;
     }
     reverse(ans.begin(),ans.end());
     cout<<ans;
}

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

int main()
{
        int A,B;
        cin>>A>>B;

        if(A+B>A-B&&A+B>A*B)
        {
                cout<<A+B<<endl;
        }
        else if(A*B>A+B&&A*B>A-B)
        {
                cout<<A*B<<endl;
        }
        else if(A+B==A*B==A-B)
        {
                cout<<A+B<<endl;
        }
        else
        {
                cout<<A-B<<endl;
        }


        return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (){
    int a;
    int b;
    cin >> a>>b ;
    if (a+b>=a-b && a+b>=a*b){
        cout<<a+b;
    } else if (a-b>=a+b && a-b>=a*b ){
        cout<<a-b;
    }else{
        cout<<a*b;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <sstream>

using namespace std;

#define For(i,a,n)	for(int i = a;i < n;i++)
#define rep(i,n)	For(i,0,n)
#define clr(n)		memset(n,0,sizeof n)
#define all(n)		(n).begin(),(n).end()

const int INF = 1e9;
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
bool cheak(int x, int y, int mx, int my){
	return x >= 0 && y >= 0 && x < mx &&  y < my;
}

struct UnionFind {
	vector<int> data;
	int maxSize;
	void init(int size){ data = vector<int>(size, -1); maxSize = 1; }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
			maxSize = max(-data[x], maxSize);
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main()
{
	int n;

	while (cin >> n && n){
		bool f[51][31]; clr(f);
		rep(i, n){
			int fi;
			cin >> fi;
			rep(j, fi){
				int t;
				cin >> t;
				f[i][t] = true;
			}
		}

		UnionFind uf[51];
		rep(i, n)uf[i].init(n);
		bool ef = false;
		For(i, 1, 31){
			vector<int> v;
			rep(j, n){
				if (f[j][i]){
					v.push_back(j);
				}
			}
			rep(j, v.size())rep(k, v.size()){
				rep(l, n){
					if (uf[v[k]].findSet(v[k],l))
					uf[v[j]].unionSet(v[j], l);
				}
			}
			rep(j, n){
				if (uf[j].maxSize == n){
					cout << i << endl;
					ef = true;
					break;
				}
			}
			if (ef)break;
		}
		if (!ef) cout << -1 << endl;
	}
	return 0;
}

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

/* #define MULTI_INPUT 0 */

void solve()
{
    int x;
    cin >> x;
    cout << 1 - x << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef MULTI_INPUT
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        solve();
    }
#else
    solve();
#endif
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    int num[3] = {3, 5, 7};
    for (int d = 3; d < 10; d++)
    {
        rep(i, pow(3, d))
        {
            int bit = i;
            int x = 0;
            bool c[3] = {0, 0, 0};
            rep(m, d)
            {
                x = x * 10 + num[bit % 3];
                c[bit % 3] = 1;
                bit /= 3;
            }
            if (c[0] && c[1] && c[2])
                v.push_back(x);
        }
    }

    int cnt = 0;
    rep(i, v.size())
    {
        if (v[i] <= n)
            cnt++;
    }

    OP(cnt);
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

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

int main(){
    string S,T;
    cin >> S;
    cin >> T;
    int start=-1;
    rep(i,S.size()-T.size()+1){
        int cnt=0;
        rep(j,T.size()){
            if (S[i+j]!=T[j] && S[i+j]!='?') continue;
            else cnt ++;
            if (cnt == T.size()){
                start = i;
                break;
            }
        }
    }
    if (start==-1) cout << "UNRESTORABLE" << endl;
    else{
        rep(i,start){
            if (S[i]=='?') cout << 'a';
            else cout << S[i];
        }
        cout << T;
        for(int i=start+T.size(); i<S.size(); i++){
            if (S[i]=='?') cout << 'a';
            else cout << S[i];           
        }
        cout << "" << endl;
    }



    return 0;
}


Measured memory_bytes: 256
from fractions import Fraction
from math import sqrt

n = int(input())
p = []

for i in range(n):
    p.append(list(map(int, input().split())))

ans = 0

for i in range(n-1):
    for j in range(i+1,n):
        flag = True
        x1,y1 = p[i][0],p[i][1]
        x2,y2 = p[j][0],p[j][1]
        d = (x2 - x1)**2 + (y2 - y1)**2
        for k in range(n):
            if (i == k or j == k):
                continue
            x3,y3 = p[k][0],p[k][1]
            e = (x3-x1)**2 + (y3-y1)**2 + (x3-x2)**2 + (y3-y2)**2
            if (d < e):
                flag = False
                break
        if flag:
            ans = sqrt(d)/2.0

if (ans != 0):
    print(ans)
    exit()

ans = 100000000

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            a,b = p[i][0],p[i][1]
            c,d = p[j][0],p[j][1]
            e,f = p[k][0],p[k][1]
            if ((a == c == e) or (b == d == f)):
                continue
            ny = (e-a) * (a*a + b*b - c*c - d*d) - (c-a) * (a*a + b*b - e*e - f*f)
            dy = 2 * (e-a) * (b-d) - 2 * (c-a) * (b-f)
            if (dy == 0):
                continue
            py = Fraction(ny,dy)
            if (c != a):
                px = 2*(b-d) * py - a*a - b*b + c*c + d*d
                px /= 2*(c-a)
            else:
                px = 2*(b-f) * py - a*a - b*b + e*e + f*f
                px /= 2*(e-a)
            r = (c-px)**2 + (d-py)**2
            flag = True
            for l in range(n):
                if (l == i or l == j or l == k):
                    continue
                x,y = p[l][0],p[l][1]
                s = (x-px)**2 + (y-py)**2
                if (r < s):
                    flag = False
                    break
            if (flag):
                q = r.numerator / r.denominator
                q = sqrt(q)
                ans = min(ans,q)

print(ans)


Measured memory_bytes: 10448
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

typedef unsigned long long ull;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while(cin>>n, n){
        int h[10]={}, v[10]={};
        rep(i,n){
            int s=0;
            rep(j,n){
                cin>>h[j];
                printf("%5d",h[j]);
                s+=h[j];
                v[j]+=h[j];
            }
            printf("%5d\n",s);
        }
        int s=0;
        rep(i,n){
            printf("%5d",v[i]);
            s+=v[i];
        }
        printf("%5d\n",s);
    }
}

Measured memory_bytes: 1144
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;

typedef long long ll;
const ll MOD_P = 1000000000 + 7;
const int MAX_N = 100000 + 2;
vector<int> G[MAX_N];

ll black[MAX_N];
ll white[MAX_N];

int dfs(int v, int v_par) {

  black[v] = 1;
  white[v] = 1;

  for (int i = 0; i < G[v].size(); i++) {
    int vn = G[v][i];
    if (vn == v_par) continue;

    dfs(vn, v);

    black[v] *= white[vn];
    black[v] %= MOD_P;

    white[v] *= (white[vn] + black[vn]);
    white[v] %= MOD_P;
  }
  
  return 0;
}

int main() {

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

  int N;
  cin >> N;

  int x, y;
  for (int i = 0; i < N - 1; i++) {
    cin >> x >> y;
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  dfs(0, -1);
  cout << (black[0] + white[0]) % MOD_P << endl;
    
  return 0;
}


Measured memory_bytes: 15716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const MAX = 1e5 + 50;
int arr[MAX];
int memo[MAX];
int n, k;

int dp(int i)
{
    if(i >= n) return 1e7;
	if(i == n - 1) return 0;
	int ret = 1e9;
	if(memo[i] != -1) return memo[i];
	for(int j = 1; j <= k && j + i< n; j++)
    {
        int temp = abs(arr[j + i] - arr[i]) + dp(j + i);
        ret = min(temp, ret);
    }
    return memo[i] = ret;
}


int main()
{
    memset(memo, -1, sizeof(memo));
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++)
    {
    	scanf("%d", &arr[i]);
    }
    printf("%d", dp(0));

	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
const int maxm = 2e5+10;
typedef long long LL;
LL A[maxn]; int n, edgecnt, head[maxn];
struct edge{int v, nxt; } E[maxm];
void init(){
    edgecnt = 0; memset(head, -1, sizeof(head));
}
void addedge(int u, int v){
    E[edgecnt].v = v, E[edgecnt].nxt = head[u], head[u] = edgecnt++;
}
LL dfs(int u, int fa){
    int cnt = 0;
    for(int i = head[u]; ~i; i = E[i].nxt){
        if(u != E[i].v) cnt++;
    }
    if(cnt == 1){
        return A[u];
    }
    LL tot = 0, x1 = 0, x2 = 0, maxw = 0, sumw;
    for(int i = head[u]; ~i; i = E[i].nxt){
        int v = E[i].v;
        if(v == fa) continue;
        sumw = dfs(v, u);
        maxw = max(maxw, sumw);
        tot += sumw;
    }
    //x1 = 2 * A[u]  - tot;
    x2 = tot - A[u];
    x1 = A[u]  -x2;
    if(x1 < 0 || x2 < 0 || A[u] < maxw || (x1 > 0 && fa == -1)){
        puts("NO");
        exit(0);
    }
    return x1;
}
int main(){
    init();
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%lld", &A[i]);
    }
    if(n == 1){
        if(A[1]) printf("NO\n");
        else printf("YES\n");
        return 0;
    }
    for(int i = 1; i < n; i++){
        int u, v;
        scanf("%d%d", &u, &v);
        addedge(u, v);
        addedge(v, u);
    }
    if(n == 2){
        if(A[1] == A[2]){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    else{
        for(int i = 1; i <= n; i++){
            int num = 0;
            for(int j = head[i]; ~j; j = E[j].nxt){
                if(E[j].v != i){
                    num++;
                }
            }
            if(num > 1){
                //printf("*%d*\n", i);
                dfs(i, -1);
                break;
            }
        }
        printf("YES\n");
    }
    return 0;
}


Measured memory_bytes: 8320
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
 char N[4];
scanf("%s",&N);
if(N[0] == N[1] && N[1] == N[2])
cout << "Yes" << endl;
else if(N[1] == N[2] && N[2] == N[3])
cout << "Yes" << endl;
else 
cout << "No" << endl;
 
 
 
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 int n;
 cin>>n;
 vector<float> v(n);
  for(int i=0; i<n; i++) {
   cin>>v.at(i);
  }
 vector<float> gyaku(n);
  for(int i=0;i<n;i++){
   gyaku.at(i)=1/v.at(i);
  }
 float gsum;
 for(int i=0;i<n;i++){
  gsum+=gyaku.at(i);
 }
 float ans;
 ans=1/gsum;
 cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
#define REP(i,j,n) for(int i=j;i<n;i++)
#define rep(i,n) REP(i,0,n)


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;
    cin >> a>> b;
    cout << a * b << endl;

}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int curx=0,cury=0,curt=0;
	for(int i=0;i<n;i++)
	{
		int t,x,y;
		cin>>t>>x>>y;
		int tm=t-curt;
		int dis=abs(curx-x)+abs(cury-y);
		if(dis<=tm)
		{
			int extra=tm-dis;
			if(extra&1)
			{
				cout<<"No";
				return 0;
			}
		}
		else
		{
			cout<<"No";
			return 0;
		}
		curx=x;
		cury=y;
		curt=t;
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 3604
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end

N, M = inputs[0].split(" ").map(&:to_i)
pS = inputs[1..-1]

# [n, cnt_wa, is_ac]
hash = Hash.new

pS.each do |ps|
  i, s = ps.split
  i = i.to_i

  if s == "WA"
    if hash[i].nil?
      hash[i] = {
        cnt_wa: 1,
        is_ac: false,
      }
    else
      unless hash[i][:is_ac]
        hash[i] = {
          cnt_wa: hash[i][:cnt_wa] + 1,
          is_ac: false,
        }
      end
    end
  elsif s == "AC"
    if hash[i].nil?
      hash[i] = {
        cnt_wa: 0,
        is_ac: true,
      }
    else
      unless hash[i][:is_ac]
        hash[i] = {
          cnt_wa: hash[i][:cnt_wa],
          is_ac: true,
        }
      end
    end
  end
end

wa = 0
ac = 0

hash.each do |i, value|
  cnt_wa = value[:cnt_wa]
  is_ac = value[:is_ac]

  if is_ac
    wa += cnt_wa
    ac += 1
  end
end

puts "#{ac} #{wa}"


Measured memory_bytes: 43900
def solve(writer):
    N, A, B, C = map(int, input().split())
    variables = {
        'A': A,
        'B': B,
        'C': C
    }

    queries = (list(input()) for _ in range(N))

    buffer = list()
    b = ''

    for i in range(N):
        if not buffer:
            t1, t2 = next(queries)
        else:
            b = buffer.pop()
            if b == 'pass':
                continue
            else:
                t1, t2 = list(b)

        v1 = variables[t1]
        v2 = variables[t2]

        if v1 == v2 == 0:
            return False
        elif v1 == v2 == 1:
            if i == N-1:
                writer.append(t1)
                return True

            nt1, nt2 = next(queries)
            if len({t1, t2, nt1, nt2}) == 2:
                buffer.append('pass')
                writer.append(t1)
                writer.append(t2)
                continue

            if t1 in {nt1, nt2}:
                variables[t1] += 1
                variables[t2] -= 1
                writer.append(t1)
            else:
                variables[t1] -= 1
                variables[t2] += 1
                writer.append(t2)

            buffer.append(''.join([nt1, nt2]))

        elif v1 > v2:
            variables[t1] -= 1
            variables[t2] += 1
            writer.append(t2)
        elif v2 > v1:
            variables[t1] += 1
            variables[t2] -= 1
            writer.append(t1)
        else:
            variables[t1] += 1
            variables[t2] -= 1
            writer.append(t1)

    return True


def main():
    writer = list()
    ok = solve(writer)
    if ok:
        print('Yes')
        for w in writer:
            print(w)
    else:
        print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9944
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    ll a[200005] = {}, c[200005] = {}, z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], c[a[i]]++;
    for (int i = 1; i <= n; i++) z += c[i] * (c[i] - 1) / 2;
    for (int i = 1; i <= n; i++) cout << z - c[a[i]] + 1 << '\n';
}


Measured memory_bytes: 6752
#include <cstdio>
#include <algorithm>
int n, m;
int b[111111];
struct Data{
	int p, y, r, id;
	bool operator<(const Data a)const{return y < a.y;}
}d[111111];
bool cmp(Data a, Data b){
	return a.id < b.id;
}
int main(){
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m; i++)
		scanf("%d %d", &d[i].p, &d[i].y), d[i].id = i;
	std::sort(d + 1, d + m + 1);
	for(int i = 1; i <= m; i++) d[i].r = ++b[d[i].p];
	std::sort(d + 1, d + m + 1, cmp);
	for(int i = 1; i <= m; i++)
		printf("%06d%06d\n", d[i].p, d[i].r);
	return 0;
}

Measured memory_bytes: 3328