akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#include <tuple>
#include <string>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
#define FORk(N) for(int k=0;k<N;++k)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
void swap(ll &a,ll &b){
  ll tmp=a;
  a=b;
  b=tmp;
}
int main(){
  ll N,M;
  cin>>N>>M;
  vector<vector<ll>> S;
  FORi(M){
    ll K;
    cin>>K;
    vector<ll> tmp(K);
    FORj(K){
      cin>>tmp[j];
    }
    S.push_back(tmp);
  }
  vector<ll> P(M);
  FORi(M){
    cin>>P[i];
  }
  ll num=0;
  FORi((ll)pow(2,N)){
    bitset<10> b(i);
    bool f=true;
    FORj(M){
      ll on=0;
      FORk(S[j].size()){
        //cout<<b[S[j][k]]<<endl;
        if(b[S[j][k]-1]){
          on++;
        }
      }
      //cout<<on<<endl;
      //cout<<P[j]<<endl<<endl;
      if((on%2)!=P[j])f=false;
    }
    if(f)num++;
  }
  cout<<num<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    map<ll, ll, greater<ll>> list;
    rep(i, n){
        cin >> a[i];
        list[a[i]]++;
    }
    rep(i, m){
        ll b, c; cin >> b >> c;
        list[c] += b;
    }
    ll ans = 0, cnt = 0;
    for(auto i : list){
        ans += i.first * i.second;
        cnt += i.second;
        if(cnt > n){
            ans -= i.first * (cnt - n);
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int lli;
#define optimize ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define forn(i,n) for(int i = 0; i<n; i++)
#define forab(i,a,b) for(int i = a; i<b; i++)
#define forll(i,a,b) for(lli i = a; i<b; i++)
#define mp make_pair
#define pb emplace_back
#define sortv(v) sort(v.begin(), v.end())
#define debug(x) cout<<#x<<" : "<<x<<endl
#define all(x) x.begin(),x.end()
const int mod1 = 1000000007;
const int mod2 = 998244353;

int main()
{
	optimize
	#ifndef ONLINE_JUDGE
	freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
	#endif

    int n;
    cin>>n;
    vector<int>l(n);
    forn(i,n)
    	cin>>l[i];

    int ans = 0;
    int x,y,z;
    forab(i,0,n-2)
    {
    	forab(j,i+1,n-1)
    	{
    		if(l[j] == l[i])
    			continue;
    		forab(k, j+1, n)
    		{
    			if(l[j] == l[k] || l[k] == l[i])
    				continue;

    			x = l[i]; y = l[j]; z = l[k];

    			if(x+y > z && x+z > y && y+z > x)
    				ans++;
    		}
    	}
    }

    cout<<ans<<endl;
    

	
	return 0;
}

Measured memory_bytes: 3660
n, k = gets.chomp.split.map(&:to_i)
h = gets.chomp.split.map(&:to_i)
INF = 10 ** 9

dp = Array.new(n + 5, INF)
dp[0] = 0

1.upto(n-1) do |i|
  1.upto(k) do |j|
    next if i - j < 0
    m = dp[i-j] + (h[i] - h[i-j]).abs
    dp[i] = m if m < dp[i]
  end
end
p dp[n-1]


Measured memory_bytes: 11268
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
const int mod = 1e9+7;
const int maxn = 4e6+5;
const double eps = 1e-6;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll kpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
bitset<maxn> bt;
int main()
{
	int n,a,sum = 0;
	scanf("%d",&n);
	bt[0] = 1;
	rep(i,0,n){
		scanf("%d",&a);
		bt |= bt<<a;
		sum += a;
	}
	rep(j,(sum+1)/2,sum+1) if(bt[j]) return printf("%d",j),0;
	return 0;
}





Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
const int mod = 1000000007;
int x;
pri_queue<ll> v;
int main(){
  cin >> x;
  for (size_t b = 1; b <= 1000; b++) {
    for (size_t p = 2; p < 10; p++) {
      ll a = pow(b,p);
      if(x >= a)v.push(a);
      else break;
    }
  }

  cout << v.top() << endl;
}


Measured memory_bytes: 256
n = int(input())
x = [int(y.strip()) for y in input().split()]
lower = min(x)
upper = max(x)
i = lower
ans = 10000*100
for i in range(upper+1):
  ttl = 0
  for j in x:
    dist = (j - i)**2
    ttl = ttl + dist
  if ttl < ans:
    ans = ttl
print(ans)

Measured memory_bytes: 9084
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<pair<int,int>>red(n);
    vector<pair<int,int>>blue(n);
    int a[n],b[n],c[n],d[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        red[i]={a[i],b[i]};
    }
    for(int i=0;i<n;i++){
        cin>>c[i]>>d[i];
        blue[i]={d[i],c[i]};
    }
    sort(red.begin(),red.end(),greater<pair<int,int>>());//赤:x座標降順
    sort(blue.begin(),blue.end());//青:y座標昇順
    int x=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<blue.size();j++){
            if(red[i].first<blue[j].second && red[i].second<blue[j].first){
                blue.erase(blue.begin()+j);
                x++;
                break;
            }
        }
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;
int main(){ 
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<set<int>> idx(26);
  rep(i,26) idx[i].insert(INF);
  rep(i,n) idx[s[i] - 'a'].insert(i);
  while (q--) {
    int f, l, r;
    char c;
    cin >> f;
    if (f == 1) {
      cin >> l >> c;
      l--;
      idx[s[l] - 'a'].erase(l);
      s[l] = c;
      idx[c - 'a'].insert(l);
    } else {
      cin >> l >> r;
      l--;
      int cnt = 0;
      for (int i = 0; i < 26; i++) {
        auto itr = idx[i].lower_bound(l);
        if (*itr < r) cnt++; 
      }
      cout << cnt << endl;
    }
  }
  return 0;
} 

Measured memory_bytes: 24196
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>

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

int main(void)
{
	int A, B;
	cin >> A >> B;
	int plug = 1;
	int ans = 0;
	while (plug < B){
		plug--;
		plug += A;
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll mn = min({a, b, c, d, e});
    cout << 4 + (n+mn-1)/mn << endl;
}

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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue
//pair…二つの値を一組
//tuple…複数の値を一組

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

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}

template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

ull ans = 0;
/*
int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}
*/
 int main() {
    int r, d, x;
    cin >> r >> d >> x;
    vector<int> v(10);
    v[0] = r * x - d;
    rep(i, 1, v.size()-1) {
        v[i] = r * v[i-1] - d;
    }
    for (auto &i: v) cout << i << endl;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100;
const int mod = 1000000007;

const int maxn = 15;
int n, m;
int dist[maxn][maxn];
int dp[1<<maxn][maxn];

int dfs(int s, int v){

    if(dp[s][v] >= 0){
        return dp[s][v];
    }

    if(s == (1<<n)-1 && v == 0){
        return dp[s][v] = 0;
    }

    int ans = inf;
    rep(u,0,n){
        if(!(s >> u & 1)){
            ans = min(ans, dfs(s | 1 << u, u) + dist[v][u]);
        }
    }

    dp[s][v] = ans;
    return ans;


}

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

    
    cin >> n >> m;

    memset(dp,-1,sizeof(dp));
    fill(dist[0],dist[0]+maxn*maxn,inf);

    

    
    rep(i,0,m){
        int f, t, c;
        cin >> f >> t >> c;
        dist[f][t] = c;
    }
    int ans = dfs(0,0);
    cout << (ans == inf ? -1 : ans) << endl;

}


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

int keisan(int ABCD, string op)
{
  vector<int> a(4);
  a.at(3) = ABCD%10;
  a.at(2) = (ABCD/10)%10;
  a.at(1) = (ABCD/100)%10;
  a.at(0) = ABCD/1000;
  
  int ans = a.at(0);
  
  for(int i=1; i<4; i++)
  {
    if(op.at(i-1) == '+')
    {
      ans += a.at(i);
    }
    else
    {
      ans -= a.at(i);
    }
  }
  
  return ans;
}
  
int main()
{
  int ABCD;
  cin >> ABCD;
  vector<int> a(4);
  a.at(3) = ABCD%10;
  a.at(2) = (ABCD/10)%10;
  a.at(1) = (ABCD/100)%10;
  a.at(0) = ABCD/1000;
  string tes = "+-";
  string op = "+++";
  
  for(int i=0; i<2; i++)
  {
    for(int j=0; j<2; j++)
    {
      for(int k=0; k<2; k++)
      {
        op.at(0) = tes.at(i);
        op.at(1) = tes.at(j);
        op.at(2) = tes.at(k);
        if(keisan(ABCD,op) == 7) break;
      }
      if(keisan(ABCD,op) == 7) break;
    }
    if(keisan(ABCD,op) == 7) break;
  }
  
  cout << a.at(0);
  for(int i=0; i<3; i++)
  {
    cout << op.at(i) << a.at(i+1);
  }
  
  cout << "=7" << endl;
  
}
  
    
  
  
  
  
  

Measured memory_bytes: 3516
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		Long[] a = new Long[n];
		for (int i = 0; i < n; i++)
			a[i] = Long.parseLong(sc.next());
		Arrays.sort(a, Comparator.reverseOrder());
		long edge1 = 0, edge2 = 0;
		int index = 0;
		for (int i = 1; i < n; i++) {
			if (a[i].equals(a[i - 1])) {
				if (edge1 == 0) {
					edge1 = a[i];
					index = i;
				}
				else if (edge2 == 0 && index != i - 1) {
					edge2 = a[i];
					break;
				}
			}
		}
		BigInteger ans = new BigInteger(Long.toString(edge1)).multiply(new BigInteger(Long.toString(edge2)));
		System.out.println(ans);
	}
}

Measured memory_bytes: 49348
n,x=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(n-1)
ans=0
for i in range(n-1):
  dp[i]=a[i]+a[i+1]
for j in range(n-2):
  if dp[j]>x:
    ans+=min(dp[j]-x,a[j+1])
    dp[j+1]-=min(dp[j]-x,a[j+1])
    dp[j]-=min(dp[j]-x,a[j+1])
if dp[n-2]>x:
  ans+=dp[n-2]-x
  dp[n-2]-=dp[n-2]-x
if dp[0]>x:
  ans+=dp[0]-x
  dp[0]-=dp[0]-x
print(ans)

Measured memory_bytes: 84928
#include <stdio.h>

int main(void)
{
	int i,n,debt=100000;
	scanf("%d",&n);
	for (i=0;i<n;i++){
		debt=debt*1.05+999;
		debt=debt/1000*1000;
	}
	printf("%d\n",debt);
	return 0;
}

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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

int main(){
	string s;
	cin >> s;
	s[1] == 'B' ? s[1] = 'R' : s[1] = 'B';
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<int,int>
#define vint vector<int>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
int read(){
	int g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
int n;
signed main(){
	n=read();
	if(n==3)cout<<"2 5 63";
	else if(n&1){
		int a[8]={6,2,10,3,9,4,8,12};
		for(int i=0;i<n;i++){
			cout<<a[i%8]<<' ';
			a[i%8]+=12;
		}
	}else{
		int a[8]={2,10,3,9,4,8,6,12};
		for(int i=0;i<n;i++){
			cout<<a[i%8]<<' ';
			a[i%8]+=12;
		}
	}return signed();
}

Measured memory_bytes: 3628
n = int(input())
s = input()

black_right, min_val = 0, 2000001
white_left = s.count('.')
ans = [white_left+black_right]

for moji in s:
    if moji == '.':
        white_left -=1
    else:
        black_right += 1
    ans.append(white_left+black_right)
    #min_val = min(min_val, white_left+black_right)

print(min(ans))

Measured memory_bytes: 11264
#include <iostream>

using namespace std;

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

    int dp[n+1];
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        dp[i] = dp[i-1] + 1;
        for (int j = 6; i - j >= 0; j *= 6) {
            dp[i] = min(dp[i], dp[i-j] + 1);
        }
        for (int j = 9; i - j >= 0; j *= 9) {
            dp[i] = min(dp[i], dp[i-j] + 1);
        }
    }

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int N;
vector<int> a;

void solve() {
    vector<int> res;
    
    for (int i = 0; i < N; ++i) {
        int pivot = -1;
        for (int j = (int)a.size()-1; j >= 0; --j) {
            if (a[j] == j) {
                pivot = j;
                break;
            }
        }
        if (pivot == -1) {
            cout << -1 << endl;
            return;
        }

        res.push_back(pivot + 1);
        a.erase(a.begin() + pivot);
    }
    reverse(res.begin(), res.end());
    for (auto v : res) cout << v << endl;
}

int main() {
    while (cin >> N) {
        a.resize(N);
        for (int i = 0; i < N; ++i) cin >> a[i] , --a[i];
        solve();
    }
}


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

int main() {

	int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
	vector<ll> h;
	vector<ll> p(a);
	for (int i = 0; i < a; i++) {
		cin >> p[i];		
	}
	sort(p.rbegin(), p.rend());
	for (int i = 0; i < x; i++) {
		h.push_back(p[i]);
	}
	vector<ll> q(b);
	for (int i = 0; i < b; i++) {
		cin >> q[i];
	}
	sort(q.rbegin(), q.rend());
	for (int i = 0; i < y; i++) {
		h.push_back(q[i]);
	}
	for (int i = 0; i < c; i++) {
		int r; cin >> r;
		h.push_back(r);
	}	
	sort(h.rbegin(), h.rend());
	ll ans = 0;
	for (int i = 0; i < x + y; i++) {
		ans += h[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9008
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int height,width;
    char dot = '.';
    char sharp = '#';
    char printChar;
    bool isOver = false;
    while(!isOver){
        cin>>height>>width;
        if(height ==0 && width == 0){
            isOver = true;
            break;
        }else{
            //add frame ops
            for(int i=0;i<height;i++){
                for(int j = 0;j<width;j++){
                    printChar = dot;
                    if((i+j)%2==0){
                        printChar = sharp;
                    }
                    cout<<printChar;
                    
                }
                cout<<endl;
            }
        }
        
        cout<<endl;
        
    
    }
	return 0;
}

Measured memory_bytes: 3076
# ABC112C - Pyramid
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    l = sorted(
        [tuple(map(int, input().rstrip().split())) for _ in range(n)],
        key=lambda x: x[2],
        reverse=True,
    )
    for x in range(0, 101):
        for y in range(0, 101):
            i, j, k = l[0]
            h = k + abs(i - x) + abs(j - y)
            for i, j, k in l[1:]:
                if k != max(h - abs(i - x) - abs(j - y), 0):
                    break
            else:
                print(x, y, h)
                return


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
lint dp[55][2505][55];
int n,A;
int ar[55];
int main(){
  cin>>n>>A;
  REP(i,n) cin>>ar[i];
  dp[0][0][0]=1;
  REP(i,n) REP(j,2505) REP(k,55) if(dp[i][j][k]){
    dp[i+1][j][k]+=dp[i][j][k];
    dp[i+1][j+ar[i]][k+1]+=dp[i][j][k];
  }
  lint res=0;
  REP(j,2505) REP(k,55) if(dp[n][j][k]){
    if(k*A==j) res+=dp[n][j][k];
  }
  --res;
  cout<<res<<endl;


  return 0;
}





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

using namespace std;

int main(void) {
  int n;
  cin >> n;

  if(n == 0) {
    cout << "0" << endl;
    return 0;
  }

  string s;
  while(n != 0) {
    if(n % (-2) == 0) {
      s.push_back('0');
    }
    else {
      s.push_back('1');
    }
    if(n % (-2) < 0) {
      n -= 2;
    }
    n /= (-2);
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}

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

using namespace std;


int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> v(N);
	for (int i = 0 ; i < N; ++i)
		cin >> v[i];
	sort(v.begin(), v.end());
	long long int s = 0;
	for (int i = K; i < v.size(); ++i)
		s += v[v.size() - i - 1];
	cout << s;


	return 0;
}


Measured memory_bytes: 3992
n, m = map(int, input().split())
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split())))
ab.sort()
money = 0
i = 0
while True:
    if ab[i][1] < m:
        money += ab[i][0]*ab[i][1]
        m -= ab[i][1]
    else:
        money += ab[i][0]*m
        break
    i += 1

print(money)


Measured memory_bytes: 60760
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
//#define =1e9 =(int)1e9
const ll mod = 1000000007;
const ll nmax=3000001;
#define int ll
int n, dp[101][2][2], d; /// prima ii daca toate cifrele is karoce ca sa vezi daca mai mare, a doua pentru transit
string s;

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>s>>d;
    dp[0][1][0]=1;

    for(int i=1; i<=s.size(); i++){
        int x=s[i-1]-'0';
        for(int md=0; md<=d-1; md++) dp[md][0][1]=dp[md][1][1]=0;
       // cout<<"XD "<<(7<x);
        for(int md=0; md<=d-1; md++){
            for(int c=0; c<=9; c++){
                //if(c==7)  cout<<"XD "<<(c<x);
                dp[((md+c)%d)][0][1]+=(dp[md][0][0]+dp[md][1][0]*(c<x));
                dp[((md+c)%d)][0][1]%=mod;
                //cout<<"xd"<<dp[((md+c)%d)][0][1];
            }
            dp[(md+x)%d][1][1]+=dp[md][1][0];
            dp[(md+x)%d][1][1]%=mod;
        }
        for(int md=0; md<=d-1; md++) dp[md][0][0]=dp[md][0][1], dp[md][1][0]=dp[md][1][1];// cout<<md<<" "<<dp[md][0][0]<<" "<<dp[md][1][0]<<endl;
    }
    cout<<(dp[0][1][0]+dp[0][0][0]+mod-1)%mod;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

bool solve() {
  ll a, v; cin >> a >> v;
  ll b, w; cin >> b >> w;
  ll t; cin >> t;
  if (v <= w) return false;
  v -= w;
  return v * t >= llabs(a - b);
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  cout << (solve() ? "YES\n" : "NO\n");

  return 0;
}


Measured memory_bytes: 3608
use std::io;

fn read_lines() -> (i32, i32) {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let input: Vec<i32> = line.split_whitespace().map(|x| x.trim().parse::<i32>().unwrap()).collect();
    return (input[0], input[1]);
 }

fn calcu_alignment(n: i32, k: i32) -> u32 {
    let mut res: u32 = k as u32;
    for _ in 1..n {
        res *= (k-1) as u32;
    }
    return res;
}

fn main() {
    let (n, k) = read_lines();
    println!("{}", calcu_alignment(n, k));
}

Measured memory_bytes: 4352
#include <cstdio>
#include <utility>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
long long f[200010], inv[200010], invf[200010];
long long comb(int n, int k) {
	if (n < 0 || k < 0 || k > n) return 0;
	return f[n] * invf[k] % mod * invf[n-k] % mod;
}
long long g(int x, int y) {
	return comb(x + y, x);
}
pair<int, int> p[3010];
long long dp[3010];
int main() {
	int h, w, n;
	scanf("%d%d%d", &h, &w, &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &p[i].first, &p[i].second);
		--p[i].first; --p[i].second;
	}
	f[0] = inv[0] = invf[0] = 1;
	f[1] = inv[1] = invf[1] = 1;
	for (int i = 2; i <= 200000; i++) {
		f[i] = f[i-1] * i % mod;
		inv[i] = mod - mod / i * inv[mod%i] % mod;
		invf[i] = invf[i-1] * inv[i] % mod;
	}
	--h; --w;
	sort(p, p + n);
	long long ans = g(h, w);
	for (int i = 0; i < n; i++) {
		dp[i] = g(p[i].first, p[i].second);
		for (int j = 0; j < n; j++) {
			if (i != j && p[i].first >= p[j].first && p[i].second >= p[j].second) {
				dp[i] -= dp[j] * g(p[i].first - p[j].first, p[i].second - p[j].second) % mod;
				if (dp[i] < 0) dp[i] += mod;
			}
		}
		ans -= dp[i] * g(h - p[i].first, w - p[i].second) % mod;
		if (ans < 0) ans += mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4864
import math
import itertools
import sys
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

h.sort(reverse=True)
ans = 0
for i in range(len(h)):
    if(h[i] < k):
        ans = i
        print(ans) 
        sys.exit()

print(len(h))

Measured memory_bytes: 12028
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <string.h>
#include <queue>
#include <functional>
using namespace std;
int main() {
	int a[203];
	int n;
	cin >> n;
	for (int i = 0; i < 2 * n; i++) {
		cin >> a[i];
	}
	sort(a, a + 2 * n);
	int ans = 0;
	for (int i = 0; i < 2*n; i+=2) {
		ans += a[i];
	}
	cout << ans;
	return 0;
}

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

typedef long long LL;
typedef pair<LL, LL> pll;

#define pb push_back
#define mp make_pair

const int N = 2e5 + 10;

int n;
LL X, D;
stack<pll> V[N];
unordered_map<LL, int> MP;

int getidx(LL v){
    if(MP.count(v)){
        return MP[v];
    }
    int m = MP.size();
    return MP[v] = m;
}

bool cross(LL L1, LL R1, LL L2, LL R2){
    return min(R1, R2) >= max(L1, L2);
}

int main(){
    scanf("%d %lld %lld", &n, &X, &D);

    if(D == 0){
        if(X == 0){
            puts("1");
        } else {
            printf("%d\n", n + 1);
        }
        return 0;
    }

    LL d = abs(D);

    MP[0] = 0;

    V[0].push(mp(0, 0));

    LL low = 0, top = 0, lft = 0, rgt = n-1;
    LL L, R, r;
    int idx;

    for(int i=1; i<=n; i++){
        low += lft;
        top += rgt;
        lft++;
        rgt--;

        r = (X * i % d + d) % d;
        L = (X * i - r) / D + low;
        R = (X * i - r) / D + top;

        idx = getidx(r);

        while(!V[idx].empty() && cross(L, R, V[idx].top().first, V[idx].top().second)){
            L = min(L, V[idx].top().first);
            R = max(R, V[idx].top().second);
            V[idx].pop();
        }

        V[idx].push(mp(L, R));
    }

    LL ans = 0;
    int m = MP.size();
    for(int i=0; i<m; i++){
        while(!V[i].empty()){
            ans = ans + V[i].top().second - V[i].top().first + 1;
            V[i].pop();
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 142920
s = input()
n = len(s)
y_id = (n+1)//2
ans = 0
if s==s[::-1]:
    ans += 1
sa = s[0:y_id-1]
if sa==sa[::-1]:
    ans += 1
sb = s[y_id:n]
if sb==sb[::-1]:
    ans += 1
if ans==3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> p(N);
  
  for (int i = 0; i < N; i++) {
    string a;
    int b;
    cin >> a >> b;
    get<0>(p.at(i)) = a;
    get<1>(p.at(i)) = -b;
    get<2>(p.at(i)) = i + 1;
  }
  
  sort(p.begin(), p.end());  
  
  for (int i = 0; i < N; i++) {
    
  	cout << get<2>(p.at(i)) << endl; 
  }
  
}

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

int main(){
	int n,k;
	int l[64];
	int ans = 0;
	cin >>n >>k;
	for(int i=0;i<n;i++){
		cin >>l[i];
	}

	int m = -1;
	int tmp = l[0];

	for(int j=0;j<k;j++){
		for (int i=1; i<n; i++) {
			if (tmp < l[i]){
				tmp = l[i];
				m = i;
//				cout << m << " " <<tmp <<endl;
			}
		}
		if(m == -1){
			l[0] = -1;
		}else{
			l[m] = -1;
		}
		ans += tmp;
		tmp = l[0];
		m = -1;
//		cout <<m << " " <<ans <<endl;
	}

	cout <<ans <<endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int N;
	cin >> N;
	int ans = 0, tmp;
	REP(i, 0, N){
		cin >> tmp;
		ans += tmp - 1;
	}
	cout << ans;
}


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

const int NMAX = 2e6;
vector<int> primes;
vector<int> prime(NMAX,0);
void sieve(){
  	for(int i = 3; i < NMAX; i += 2){
     	prime[i] = 1; 
    }
  	prime[2]=1;
  	for(int i = 3; i*i < NMAX; i += 2){
     	if(prime[i]){
         	for(int j = i*i; j < NMAX; j+=2*i){
             	prime[j] = 0; 
            }
        }
    }
  	primes.push_back(2);
  	for(int i = 3; i < NMAX; i += 2){
     	if(prime[i])
          	primes.push_back(i);
    } 
}

int max_score(int n, int p){
    int cnt = 0;
    while(n % p == 0){
        cnt++;
        n /= p;
    }
    // 1 + 2 + ... k = (k * (k+1))/2 <= cnt
    int si = 1, ei = cnt;
    int ans = 1;
    while(si <= ei){
        int mid = (si + ei)>>1;
        if((mid * (mid+1) / 2LL) <= cnt){
            ans = mid;
            si = mid + 1;
        }
        else{
            ei = mid - 1;
        }
    }
    return ans;
}

signed main(){
  	sieve();
 	int n;
  	cin>>n;
  	vector<int> factors;
  	int u = 0, v = primes[u];
  	int N = n;
  	while( v*v <= n){
     	if(n % v == 0){
         	factors.push_back(v);
          	while(n % v == 0){
             	n /= v; 
            }
        }
      u++;
      v = primes[u];
    }
  	if(n != 1){
     	factors.push_back(n); 
    }
    int ans = 0;
    for(int i : factors){
        ans += max_score(N, i);
    }
    cout << ans << endl;
}
// 11 * 

Measured memory_bytes: 20772
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

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 = 1e18+1;

int B[30][100002], S[100002];

int main() {
    int N, C; cin >> N >> C;
    vector<int> s(N), t(N), c(N);
    for (int i = 0; i < N; i++) cin >> s[i] >> t[i] >> c[i];

    for (int i = 0; i < N; i++) {
        B[c[i]-1][s[i]] += 1;
        B[c[i]-1][t[i]] += -1;
    }
    
    for (int c = 0; c < C; c++) {
        for (int i = 0; i < 1e5+1; i++) {
            if (B[c][i] == -1) {
                B[c][i+1] -= 1;
                B[c][i] += 1;
                i++;
            }
        }
    }

    for (int c = 0; c < C; c++) {
        S[0] += B[c][0];
    }
    
    for (int i = 1; i < 1e5+1; i++) {
        S[i] = S[i-1];
        for (int c = 0; c < C; c++) {
            S[i] += B[c][i];
        }
    }
    



    int res = 1;
    for (int i = 0; i < 1e5+1; i++) {
        chmax(res, S[i]);
    }
    cout << res << endl;
}


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

int main(){
  int n,m;

  cin >> n >> m;

  int ar1[100][100];
  int *ar2 = new int[m];
  
  for(int i = 0; i<n ; ++i){
    for(int k = 0; k<m ; ++k){
      cin >> ar1[i][k];
    }
  }

  for(int i = 0; i<m ; ++i){
    cin >> ar2[i];
  }

  int ans=0;
  for(int i = 0; i<n ; ++i){
      for(int l = 0; l<m; ++l){
	ans += ar1[i][l]*ar2[l];
      }

      cout << ans << endl;
      ans = 0;
  }


  delete[] ar2;

  return 0;
}



Measured memory_bytes: 3132
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		sc.close();

		Set<Integer> set = new HashSet<>();
		for(int i = 1;;i++) {
			int mod = (A * i)%B;
			int oldSize = set.size();
			set.add(mod);
			int newSize = set.size();
			if(oldSize == newSize) {
				break;
			}
		}
		String result = "NO";
		if(set.contains(C)) {
			result = "YES";
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 21840
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;


int main(){

  int n;
  cin >> n;
  
  vector <int>v;
  v.push_back(1);
  
  int V = 6;
  while(1){
    if(V > n) break;
    v.push_back(V);
    V *= 6;
  }
  
  V = 9;
  while(1){
    if(V > n) break;
    v.push_back(V);
    V *= 9;
  }  

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

  int ans[n+1];
  REP(i,n+1) ans[i] = MOD;
  
  REP(i,v.size()){
    ans[v[i]] = 1;
  }
  
  int cnt = 500;
  while(cnt > 0){
  REP(i,v.size()){
    FOR(j,v[i],n+1){
      ans[j] = min(ans[j],ans[j-v[i]]+1);
    }
  }
    cnt--;
  }
  
  
 //  REP(i,v.size()) debug(v[i]); 
    
  cout << ans[n] << endl;

 return 0;
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

//UnionFind
// グラフを保持する必要はない。このままはっつけていける
// 計算量はほぼ定数とみなせる
struct UnionFind
{
    vector<int> d;
    UnionFind(int n = 0) : d(n, -1) {}
    int root(int x)
    {
        if (d[x] < 0)
            return x;
        return d[x] = root(d[x]);
    }
    // 辺情報から2点をくっつける
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
        {
            return false;
        }
        if (-d[x] < -d[y])
            swap(x, y); //y.size()が小でx.size()が大にしておきたい
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -d[root(x)]; }
};
//
int main()
{
    int n,m;cin >> n >> m;
    vector<int> p(n+1);
    for (int i = 1; i < n+1; i++)
    {
        cin >> p[i];
    }
    vector<P> sousa(m);rep(i,m) cin >> sousa[i].first >> sousa[i].second;
    UnionFind uf(n+1);
    rep(i,m)
    {
        uf.unite(sousa[i].first, sousa[i].second);
    }
    int counter = 0;
    for (int i = 1; i < n + 1; i++)
    {
        if(uf.same(i, p[i]))counter++;
    }
    cout << counter << endl;
}

Measured memory_bytes: 4784
package main

import "fmt"

func main() {
	var p, q, r int
	fmt.Scan(&p, &q, &r)
	max := 0
	if max < p {
		max = p
	}
	if max < q {
		max = q
	}
	if max < r {
		max = r
	}
	fmt.Println(p + q + r - max)
}


Measured memory_bytes: 512
def resolve():
    import math
    x = int(input())

    def lcm(a, b):
        return (a * b) // math.gcd(a, b)

    if 360 % x == 0:
        print(360 // x)
    else:
        print(lcm(360, x) // x)


if 'unittest' not in globals():
    resolve()

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int n, m;
vector<int> graph[10];

int dfs(int u, int p, int bit)
{
  if(bit == (1<<n)-1) return 1;
  int ret = 0;
  for(int v : graph[u]) {
    if(v == p) continue;
    if(!((bit >> v) & 1)) ret += dfs(v, u, bit | (1<<v));
  }
  return ret;
}

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

  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  cout << dfs(0, -1, 1) << endl;

  return 0;
}


Measured memory_bytes: 256
use std::io;
use std::cmp;
use std::collections::HashMap;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    let mut cnt = 0;
    for c in read_line().chars() {
        if c == '1' {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
	int n[300010] = {0};
	int N,Q;
	cin >> N >> Q;
	for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        n[a] = a;
	}
	for(int i = 1; i < 300010; i++)n[i]=max(n[i],n[i-1]);
	int ans = 0;
	for(int i = 0; i < Q; i++){
        int q;
        cin >> q;
        for(int j = q; j <= 300010; j+=q){
            ans = max(n[j-1]%q,ans);
        }
        cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2340
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

using namespace std;
using ll = long long;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabCout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headCout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabHeadCout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
//#define int long long
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divUp(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

int Main()
{
	int N, K;
	cin >> N >> K;
	vector<int> h(N);
	rep(i, N)	cin >> h.at(i);

	vector<int> s(N, INF);
	s.at(0) = 0;

	for (int i = 0; i < N; i++)
	{
		for (int j = 1; j <= K && i + j < N; j++)
		{
			chmin(s[i + j], s[i] + abs(h[i] - h[i + j]));
		}
	}

	for (int i = 0; i < N; i++)
	{
		debug_cout(i);
		debug_tabCout(1, s.at(i));
	}

	cout << s.at(N - 1) << endl;

	return 0;
}

/*****/

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

	//std::cout << std::fixed << std::setprecision(10);

	Main();

	return 0;
}


Measured memory_bytes: 1024
N,M = map(int, input().split())
ans = 0
S = [""]*N
for _ in range(M):
  s, c = map(int,input().split())
  if S[s-1] == "" or S[s-1] == c:
    S[s-1] = c
  elif S[s-1] != "" and S[s-1] != c:
    print(-1)
    exit(0)
if N == 3:
  if S[0] == "":
    S[0] = 1
  if S[0] == 0:
    print(-1)
    exit(0)
  if S[1] == "":
    S[1] = 0
  if S[2] == "":
    S[2] = 0
elif N == 2:
  if S[0] == "":
    S[0] = 1
  if S[0] == 0:
    print(-1)
    exit(0)
  if S[1] == "":
    S[1] = 0
elif N == 1:
  if S[0] == "":
    S[0] = 0
print(''.join(map(str,S)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int N,X;
  cin >> N >> X;
  int sum = 0;
  int d = 0;
  
  for(int i = 0; i < N+1 ; i++){
    
    if(d > X){
      break;
    }
    sum++;
    
    int L;
    cin >> L;
    d += L;
  }
  
  cout << sum << endl;
}
    
  
  

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

int main(){
    int n,k[1000],p[1000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>k[i]>>p[i];
    if(k[i]%p[i]==0)
        cout<<p[i]<<endl;
    else
        cout<<k[i]%p[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int A[20], B[50], C[50];
    for (int i = 0; i < N; i++) {
        cin >> A[i];    
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];    
    }
    for (int i = 0; i < N - 1; i++) {
        cin >> C[i];    
    }
    long long ret = 0;
    int prev = -999;
    for (int i = 0; i < N; i++) {
        int j = A[i] - 1;
        ret += B[j];
        if (prev == j - 1) {
            ret += C[prev];
        }
        prev = j;
    }

    cout << ret << "\n";

    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

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

  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];

  int res = 0;
  reps(i,1,n-1) {
    if(p[i-1] < p[i] && p[i] < p[i+1]) res++;
    if(p[i-1] > p[i] && p[i] > p[i+1]) res++;
  }

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256