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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n;
  LL mod;
  vector<LL> ans;
  struct Edge {
    int to, rev;
    LL val;
  };
  vector<vector<Edge>> t;

  Solver2(LL n, LL m) : n(n), mod(m), ans(n), t(n){};

  void solve() {
    for (int i = 0; i < n - 1; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      t[a].push_back({b, (int)t[b].size(), 1});
      t[b].push_back({a, (int)t[a].size() - 1, 1});
    }
    if (n == 1) {
      cout << 1 << endl;
      return;
    }
    dfs(0);
    dfs2(0);
    for (int i = 0; i < n; ++i) {
      cout << ans[i] << endl;
    }
  }
  void dfs(int v, int p = -1) {
    LL res = 1;
    int par;
    for (int i = 0; i < (int)t[v].size(); ++i) {
      if (t[v][i].to != p) {
        dfs(t[v][i].to, v);
        res *= t[v][i].val + 1;
        res %= mod;
      } else {
        par = i;
      }
    }
    if (p == -1) {
      ans[v] = res;
    } else {
      t[p][t[v][par].rev].val = res;
    }
  }
  void dfs2(int v, int p = -1) {
    LL res = 1;
    for (int i = 0; i < t[v].size(); ++i) {
      res *= t[v][i].val + 1;
      res %= mod;
    }
    ans[v] = res;

    vector<LL> prodl(t[v].size(), 1), prodr(t[v].size(), 1);
    prodl[0] = (t[v][0].val + 1) % mod;
    for (int i = 1; i < t[v].size(); ++i) {
      prodl[i] = prodl[i - 1] * (t[v][i].val + 1) % mod;
    }
    prodr[t[v].size() - 1] = (t[v][t[v].size() - 1].val + 1) % mod;
    for (int i = (int)t[v].size() - 2; i >= 0; --i) {
      prodr[i] = prodr[i + 1] * (t[v][i].val + 1) % mod;
    }

    for (int i = 0; i < t[v].size(); ++i) {
      if (t[v][i].to != p) {
        if (i > 0) {
          t[t[v][i].to][t[v][i].rev].val *= prodl[i - 1];
          t[t[v][i].to][t[v][i].rev].val %= mod;
        }
        if (i < (int)t[v].size() - 1) {
          t[t[v][i].to][t[v][i].rev].val *= prodr[i + 1];
          t[t[v][i].to][t[v][i].rev].val %= mod;
        }
        dfs2(t[v][i].to, v);
      }
    }
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


Measured memory_bytes: 17792
#include <bits/stdc++.h>
#define INF 1e9
#define MAX_V 1001
using namespace std;
typedef map<int,int> M;
typedef M::iterator Mit;
M G[MAX_V],rG[MAX_V],g[MAX_V];
int used[MAX_V];  

int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  
  for(Mit it=G[v].begin();it!=G[v].end() ;it++){
    int to=it->first;
    int &cap=it->second;
    if(!used[to] && cap > 0){
      int d = dfs(to ,t , min(f,cap));
      if(d > 0){
	cap -= d;
	G[to][v]+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}

bool visited[MAX_V];
void visit(int pos){
  if(visited[pos])return;
  visited[pos]=1;
  for(Mit it=rG[pos].begin();it!=rG[pos].end() ;it++)visit(it->first);
}

int check2(int pos){
  if(used[pos]++) return 0;
  int res=0; 
  for(Mit it=G[pos].begin();it!=G[pos].end() ;it++)
    if(it->second)res+=check2(it->first);
  
  for(Mit it=g[pos].begin();it!=g[pos].end() ;it++)
    res+=(it->second)*visited[it->first];
  
  return res;
}

int main(){
  while(1){
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    if(!n&&!m&&!s&&!t)break;
    s--,t--;
    for(int i=0;i<n;i++) rG[i].clear(),G[i].clear(),g[i].clear();
    
    for(int i=0,a,b;i<m;i++){
      cin>>a>>b;
      a--,b--;
      G[a][b]++;
      g[b][a]++;
    }

    int mx=max_flow(s,t);
    for(int i=0;i<n;i++)
      for(Mit it=G[i].begin();it!=G[i].end() ;it++){
	int to=it->first,cap=it->second;
	if(cap)rG[to][i]=cap;
      }
    
    memset(visited,0,sizeof(visited));
    memset(used,0,sizeof(used));
    visit(t);
    int cnt=check2(s);
    cout<<mx+(cnt>0)<<" "<<cnt<<endl;
  }
  
}

Measured memory_bytes: 4928
program main;
var x,i : longint;
    sum : int64;
begin
    sum:=0;
    readln(x);
    for i := 1 to x do begin
        sum := sum + i;
        if i mod 3 = 0
        then sum := sum - i
            else if i mod 5 = 0
                then sum := sum - i;
    end;
    writeln(sum);
end.

Measured memory_bytes: 1388
N,X,Y=map(int,input().split())
X-=1#0-indexへ
Y-=1
dist=[0]*(N+1)
for i in range(N):
  for j in range(i+1,N):
    d=min(j-i,abs(j-X)+1+abs(i-Y),abs(j-Y)+1+abs(i-X))
    #通常ルートとバイパスを通った時を比べて小さい方を取る
    dist[d]+=1#該当の距離に相応するパスの個数を１個追加する
for i in range(1,N):#距離が1以上のパスの個数を順番に出力
  print(dist[i])

Measured memory_bytes: 3572
def main():

    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    tot =sum(A)
    v = sum([v >= tot/4/M for v in A])
    if v >= M:
        return 'Yes'
    return 'No'

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 38256
#include <iostream>
#include <limits.h>
#include <vector>

using namespace std;

int main()
{
  int N;

  cin >> N;

  vector<short> V,C;

  for (int n=0; n<N; n++) {
    short v;
    cin >> v;
    V.push_back(v);
  }

  for (int n=0; n<N; n++) {
    short c;
    cin >> c;
    C.push_back(c);
  }

  int ans = 0;
  
  for (int n=0; n<N; n++) {
    if (V[n]-C[n]>0)
      ans += (V[n]-C[n]);
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 888
#include<stdio.h>

int parent(int);
int left(int);
int right(int);

int main(){
	int n,i,a[100005];

	scanf("%d",&n);

	for(i = 0; i < n ; i++){
		scanf("%d",&a[i+1]);
	}

	for(i = 0; i < n ; i++){
		printf("node %d: key = %d, ",i+1,a[i+1]);

		if(parent(i+1) >= 1)printf("parent key = %d, ",a[parent(i+1)]);
		if(left(i+1) <= n)printf("left key = %d, ",a[left(i+1)]);
		if(right(i+1) <= n)printf("right key = %d, ",a[right(i+1)]);
		printf("\n");
	}
	return 0;
}

int parent(int z){
	return z / 2;
}
int left(int z){
	return z * 2;
}
int right(int z){
	return z * 2 +1;
}



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

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

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

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

//Hang in there!

using namespace std;


int main() {
	int A, B, C;
	cin >> A >> B >> C;
	cout << max({ A + B,A - B,A * B }) << endl;
}



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

int main(){
  string mojiretu="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  //char mojiretu[]={'A','B','C','D','E','F','G','H',
  //	 'I','J','K','L','M','N','O','P',
  //		   'Q','R','S','T','U','V','W','X','Y','Z'};
  int i,j;
  string moji;
  cin >> moji;
  int l = moji.size();
  int len = mojiretu.size();
  for(i = 0; i < l; i++){
    if(moji[i]=='A'){
      moji[i]='X';
      continue;
    }
    if(moji[i]=='B'){
      moji[i]='Y';
      continue;
    }
    if(moji[i]=='C'){
      moji[i]='Z';
      continue;
    }
    
    for(j = 0; j < len; j++){
      if(moji[i]==mojiretu[j]){
	moji[i]=mojiretu[j-3];
      }
    }
  }
  
  for(i = 0; i < l; i++){
    cout << moji[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll findTrailingZeros(ll n)
{
    ll cnt = 0;
    for (ll i = 5; n / i >= 1; i *= 5)
        cnt += n / i;

    return cnt;
}
int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t;
	t=1;
	while(t--)
    {
        ll n,m;
        cin>>n>>m;
        cout<<min(n%m , (m-n%m)%m);
    }
}


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

using namespace std;
#define ll long long int



vector<vector<int>> v;
vector<int> vv;
vector<int> a,b,c,d;
int n,m,q;
ll ans;
void fun(int idx, int sz){
    if(sz==n){
        ll cnt = 0;
        for(int i=0;i<q;i++){
            if(vv[b[i]]-vv[a[i]]==c[i]){
                cnt+=(ll)d[i];
            }
        }
        ans = max(ans, cnt);
        return;
    }
    for(int i=idx;i<=m;i++){
        vv.push_back(i);
        fun(i,sz+1);
        vv.pop_back();
    }
}
int main()
{
    ans=0;
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for(int i=0;i<q;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    fun(1,0);
    cout << ans << endl;
}


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

using namespace std;

int main()
{
	long long n, k;
	cin >> n >> k;
	vector<long long> v((int)1e5+1, 0);
	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		v[a] += b;
	}
	long long i = 1, j = 0;
	while (i < v.size() && j < k)
	{
		j += min(k-j, v[i]);
		i++;
	}
	cout << i-1 << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

ll n,t,ma,mi = 10000000000,cou = 1,sa;

int main()
{
	cin >> n >> t;
	
	REP(i,n)
	{
		ll a;cin>> a;
		if(a - mi > sa)
		{
			sa = a - mi;
			cou = 1;
		}
		else if(a - mi == sa)cou++;
		
		mi = min(mi,a);
		ma = max(ma,a);
	}
	
	cout << cou << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    R, G, B, N = [int(x) for x in input().split()]

    ans = 0
    f = False
    for i in range(N + 1):
        if i * R > N:
            break
        for j in range(N + 1):
            if i * R + j * G > N:
                break

            if (N - (i * R + j * G)) % B == 0:
                ans += 1

    print(ans)



if __name__ == '__main__':
    main()



Measured memory_bytes: 9068
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include <random>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

ll h,w,cnt=0,res=0;
char field[500][500];
set<pll> st;
bool visited[410][410];
ll black=0,white=0;

void dfs(ll x, ll y){
    visited[x][y]=true;
    if(field[x][y]=='#') black++;
    else white++;
    rep(i,4){
        ll nx=x+dx[i],ny=y+dy[i];
        if(visited[nx][ny]) continue;
        if(field[nx][ny]==field[x][y]) continue;
        if(nx<0||nx>=h||ny<0||ny>=w) continue;
        dfs(nx,ny);
    }
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cin>>h>>w;
    ll ans=0;
    vector<pll> v;
    rep(i,h){
        rep(j,w){
            cin>>field[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            if(field[i][j]=='.') continue;
            if(visited[i][j]) continue;
            black=0,white=0;
            dfs(i,j);
            ans+=black*white;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pr;
const int maxn=3e5+10;
map<char,char>vis;
int main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;
  cin>>s;
  int ans=0,num=0;
  for(int i=0;i<s.length();i++){

     while(i<s.length()&&(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C')){
       num++;
       i++;
     }
     ans=max(num,ans);
     num=0;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
#define INF int(1e9)

template<class T,class U> ostream& operator<<(ostream& ost, const pair<T,U> &p) { ost << "(" << p.first << ", " << p.second << ")"; return ost; }
#define ostream_container { ost << "{"; for(const auto &t : v) { if (&t != &*v.begin()) ost << ", "; ost << t; } ost << "}"; return ost; }
template<class T> ostream& operator<<(ostream &ost, const vector<T> &v) ostream_container
template<class T> ostream& operator<<(ostream &ost, const set<T> &v) ostream_container
template<class T,class U> ostream& operator<<(ostream &ost, const map<T,U> &v) ostream_container

template<class H> void recursive_debug(string s, H h) {
    cerr << "\033[33m" << s << " = " << h << endl << "\033[m";
}
template<class H,class... T> void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << "\033[33m" << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}
#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)


int main(void) {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    a.push_back(0);
    ll m = 1000;
    ll s = 0;
    rep(i,n){
        if (a[i] < a[i+1]) {
            s += m / a[i];
            m -= (m / a[i])*a[i];
        }
        if (a[i] > a[i+1]) {
            m += s*a[i];
            s = 0;
        }
    }
    cout << m << endl;
    return 0;
}


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

using namespace std;

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

#define int ll

int d;
int c[26];
int s[365][26];

main(){
	cin >> d;
	for(int i=0;i<26;i++) cin >> c[i];
	for(int i=0;i<26;i++){
		for(int j=0;j<d;j++){
			cin >> s[j][i];
		}
	}

	for(int i=0;i<d;i++){
		cout << i%26 + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3704
#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);

int main(){
    ll n;
    cin >> n;
    map<ll, ll> l;
    rep(i, n){
        ll a;
        cin >> a;
        l[a]++;
    }
    ll m;
    cin >> m;
    vector<ll> o(m);
    rep(i, m) cin >> o[i];
    sort(o.begin(), o.end());
    bool z = true;
    rep(i, m){
        if(l.count(o[i]) && l[o[i]] > 0) l[o[i]]--;
        else{
            z = false;
            break;
        }
    }
    if(z) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 14336
#include<iostream>
#include<vector>
using namespace std;
long long dp[1000000];
int main(){
  int n;
  cin>>n;
  long long  a[n];
  for(int i=0;i<n;i++) {
    cin>>a[i];
    dp[i]=100000000000;
  }
    dp[0] = 0;
  for(int i=1;i<n;i++){
    if(dp[i] > dp[i-1]+llabs(a[i]-a[i-1])) {dp[i] = dp[i-1]+llabs(a[i]-a[i-1]);}
      if(i>1){
        if(dp[i] > dp[i-2]+llabs(a[i]-a[i-2])) {dp[i] = dp[i-2]+llabs(a[i]-a[i-2]);}
      }
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#define M 200
int u[M][M];
int main(){
  int i,n,j,k,a,b;


  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&a,&j);
    for(k=0;k<j;k++){
      scanf("%d",&b);
      u[a-1][b-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      printf("%d ",u[i][j]);
    }
    printf("%d\n",u[i][j]);
  }


  return 0;
}

Measured memory_bytes: 676
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)
jogen=(s-1)//(4*m)

erabi=0

for i in range(n):
    if(a[i]>jogen):
        erabi+=1

if(erabi>=m):
    print("Yes")
else:
    print("No")

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

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


bool check(map<int,int>& cnt){
    if(cnt.size() < 4) return false;
    for(auto p: cnt){
        if(p.second >= 3) return false;
    }
    return true;
}

int main(){
    map<int,int> cnt;
    for(LL i = 0; i < 6; ++i){
        int v;
        cin >> v;
        cnt[v] += 1;
    }
    if(check(cnt)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
  long long n;
  scanf("%lld",&n);
  long long a[n+1];
  for(long long i=1;i<=n;i++)scanf("%lld",&a[i]);
  
  long long money=1000,kabu=0;
  
  long long min[40],max[40],m=0,M=0;
  
  for(long long i=1;i<=40;i++){
    min[i]=0;
    max[i]=0;
  }
  
  if(a[1]<a[2]){min[1]=1;m+=1;}
  
  for(long long i=2;i<=n-1;i++){
    if(a[i]<a[i+1] && a[i]<=a[i-1]){min[m+1]=i;m+=1;}
    if(a[i]>=a[i+1] && a[i]>a[i-1]){max[M+1]=i;M+=1;}
  }
  
  if(a[n-1]<a[n]){max[M+1]=n;}
  
  for(long long i=1;i<=n;i++){
    for(long long j=1;j<=m;j++){
      if(i==min[j]){
        kabu=money/a[i];
        money%=a[i];
      }
      if(i==max[j]){
         money+=kabu*a[i];
        kabu=0;
      }
    }
  }
  printf("%lld",money);
  return 0;
}

Measured memory_bytes: 2156
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

# 多次元配列
# dp = [[0] * 3 for _ in range(5)]
d = {"SUN":7,"MON":6,"TUE":5,"WED":4,"THU":3,"FRI":2,"SAT":1}
# 入力を受け取る
print(d[input()])


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

using namespace std;
typedef long long ll;




int main()
{
    
    int N;cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    sort(all(a));
    vector<pair<int, int>> x;
    x.push_back(make_pair(a[0], 0));
    rep(i,N){
        if(x.back().first != a[i]){
            x.push_back(make_pair(a[i], 1));
        }else{
            x.back().second++;
        }
    }
    
    if(x.size() == 3 && ((x[0].first ^ x[1].first) == x[2].first) && N%3==0 && x[1].second == x[2].second && x[1].second == x[0].second) cout << "Yes" << endl;
    else if(x.size() == 2 && x[0].first*x[1].first == 0 && N%3==0 && x[0].second*2 == x[1].second) cout << "Yes" << endl;
    else if(x.size() == 1 && x[0].first == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    //rep(i,int(x.size())) cout << x[i].first << " " << x[i].second << endl;
    return 0;
}



Measured memory_bytes: 1656
package main

import (
        "fmt"
)

func solution(s int) int {
        memo := make(map[int]bool, 0)
        memo[s] = true
        i := 2
        b := s
        for {
                a := helper(b)
                i++
                b = a
                if memo[a] {
                        break
                } else {
                        memo[a] = true
                }
        }
        return i - 1
}

func helper(n int) int {
        if n%2 == 0 {
                return n / 2
        }
        return 3*n + 1
}

func main() {
        var s int
        fmt.Scan(&s)
        fmt.Println(solution(s))
}

Measured memory_bytes: 512
N = int(input())
a_list = list(map(int, input().strip().split()))
b_list = list(map(int, input().strip().split()))
c_list = list(map(int, input().strip().split()))

satisfied = 0

prev = -10
for i in range(N):
	a = a_list[i]
	satisfied += b_list[a - 1]
	if prev + 1 == a:
		satisfied += c_list[prev - 1]
	prev = a

print(satisfied)


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

int main() {
	string a, b; 
  	int X;
  	cin >> a >> b >> X;
  	string ans = "No";
  
    X = stoi(a + b); 
  
  for(int i = 1; i < 1000; i++){
   if( X ==  i * i ){
     ans = "Yes";
     break;
   }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
  int main()
{  int a,b,c;
   scanf("%d%d%d",&a,&b,&c);
   if (a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5)
   {printf("YES");} 
   else {printf("NO");}
   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!
 
int main() {
    int s;
    cin >> s;
    int ans = 1;
    while (s > 4 || s == 3) {
        s = (s % 2 == 0 ? s / 2 : s * 3 + 1 );
        ans++;
    }
    cout << ans + 3 << endl;
}

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

long long n, m;
vector<pair<long long, long long>> v;

long long solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < n; ++i) {
    long long a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0, now = 0;
  for(int i = 0; i < n; ++i) {
    ans += min(m - now, v[i].second) * v[i].first;
    now += min(m - now, v[i].second);
    if(now == m) break;
  }
  return ans;
}

Measured memory_bytes: 2420
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<numeric>
#include<limits>
#include <cstdint>
#include<stack>
#include<queue>
using namespace std;
#define ll long long int
#define rep(N) for(ll i=0;i<N;i++)
#define rep2(N1,N2) for(ll i=0;i<N1;i++)for(ll j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(ll i=0;i<N1;i++)for(ll j=0;j<N2;j++)for(ll k=0;k<N3;k++)
#define For(i,N) for(ll i=0;i<N;i++)

void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int ctoi(char c) {
	return c - '0';
}

ll kai(ll x) {
	ll a = 1;
	if (x <= 0)
		return 1;
	else {
		for (ll i = 0; i < x; i++)
			a = a * (i + 1);
		return a;
	}
}

ll rui(ll x, ll y) {
	ll a = 1;
	for (ll i = 0; i < y; i++)
		a = a * x;
	return a;
}
const int nmax = 150;
int cccc[nmax][nmax];
ll comb(ll n, ll k) {
	if (n < k) {
		cout << "error n<k" << endl;
		return -1;
	}
	if (cccc[n][k] > 0)return cccc[n][k];
	if (k == 0 || n == k)return 1;
	return cccc[n][k] = comb(n - 1, k - 1) + comb(n - 1, k);
}

ll keta(ll a) {
	ll i = 1;
	while (1) {
		if (a < pow((ll)10, i))
			return i;
		i++;
	}
}
vector<ll> v;
ll n, m;
//m進数全探索
ll inc(ll a = n - 1) {
	if (a == 0 && v[0] == m) {
		v[0] = -1;
		return v[0];
	}
	if (v[a] == m) {
		v[a] = 0;
		inc(a - 1);
		return v[a];
	}
	else {
		++v[a];
		return v[a];
	}
}

ll mod = 1000000007;

ll modpowl(ll a, ll b) {
	if (b == 0) {

		return 1;
	}
	if (b == 1) {

		return a;
	}
	if (b >= 2) {
		if (b % 2 == 0) {
			ll c = modpowl((a*a) % mod, b / 2);
			c = c % mod;

			return c;
		}
		else {
			ll c = (modpowl((a*a) % mod, b / 2) % mod)*a;
			c = c % mod;

			return c;
		}
	}
}
ll gyo(ll N, ll A, ll B, ll y) {
	if (A != y && B != y)
		return y;
	else if (A == y)
		return B;
	else
		return A;
}

ll retsu(ll N, ll A, ll B, ll x) {
	if (A != x && B != x)
		return x;
	else if (A == x)
		return B;
	else
		return A;
}

pair<ll,ll> tenchi(ll x, ll y) {
	return make_pair(y, x);
}
int main() {
	cout.precision(20);
	ll N, M;
	cin >> N >> M;
	ll flag = 1;
	if (N != M)
		flag = 0;
	Yn(flag);
}




Measured memory_bytes: 256
# https://atcoder.jp/contests/abc145/tasks/abc145_d

X, Y = map(int, input().split())
p = 10 ** 9 + 7

if (X + Y)%3 != 0:
    print(0)
    exit()

n = (2*X - Y) / 3
m = (2*Y - X) / 3

if n < 0 or m < 0:
    print(0)
    exit()


# 2項係数
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0

    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p

p = 10 ** 9 + 7
N = 10 ** 6

# 階乗の配列 i番目の項目はi!
fact = [1, 1]

# 逆元の配列 i番目の項目は(i!)^(-1)
factinv = [1, 1]

# 逆元計算用の配列 i番目の項目は
# mod pを法とし、iの逆元((i)^(-1))
inv = [0, 1]

for i in range(2, N+1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

print(cmb(int(n + m), int(m), p))


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

using namespace std;

int main()
{
  int h, w, ah, aw;
  while(cin >> h >> w, h || w){
    ah = aw = 1000;
    for(int i = 1; i <= 150; i++){
      for(int j = i+1; j <= 150; j++){
	if(i*i + j*j > h*h + w*w || i*i + j*j == h*h + w*w && i > h){
	  if(i*i + j*j < ah*ah + aw*aw || i*i + j*j == ah*ah + aw*aw && i < ah) ah = i, aw = j;	  
	}
      }
    }
    cout << ah << " " << aw << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 int main(){
 int a,b,c;
   string s;
 cin>>a>>b>>c;
   if(a==b&&a==c)cout <<"No"<<endl;
   else if(a!=b&&a!=c&&b!=c)cout <<"No"<<endl;
   else cout <<"Yes"<<endl;
 }


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  
  ll h, w; cin >> h >> w;
  vector<vector<ll>> a(h, vector<ll>(w));
  vector<vector<ll>> b(h, vector<ll>(w));
  vector<vector<ll>> c(h, vector<ll>(w));
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
    }
  }
  rep(i, h) {
    rep(j, w) {
      cin >> b[i][j];
    }
  }
  rep(i, h) {
    rep(j, w) {
      c[i][j] = abs(a[i][j] - b[i][j]);
    }
  }

  vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w,vector<bool>(80 * (h + w) + 1, false)));
  dp[0][0][c[0][0]] = true;
  rep(i, h) {
    rep(j, w) {
      rep(k, 80 * (h + w) + 1) {
        if (0 <= i + 1 && i + 1 < h && dp[i][j][k]) {
          if (0 <= k + c[i + 1][j] && k + c[i + 1][j] <= 80 * (h + w)) dp[i + 1][j][k + c[i + 1][j]] = true;
          if (0 <= abs(k - c[i + 1][j]) && abs(k - c[i + 1][j]) <= 80 * (h + w)) dp[i + 1][j][abs(k - c[i + 1][j])] = true;
        }
        if (0 <= j + 1 && j + 1 < w && dp[i][j][k]) {
          if (0 <= k + c[i][j + 1] && k + c[i][j + 1] <= 80 * (h + w)) dp[i][j + 1][k + c[i][j + 1]] = true;
          if (0 <= abs(k - c[i][j + 1]) && abs(k - c[i][j + 1]) <= 80 * (h + w)) dp[i][j + 1][abs(k - c[i][j + 1])] = true;
        }
      }
    }
  }
  rep(k, 80 * (h + w) + 1) {
    if (dp[h - 1][w - 1][k]) {
      cout << k << endl;
      exit(0);
    }
  }
}


Measured memory_bytes: 14528
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<vector<int>> E(N);
    vector<vector<long long>> C(N);

    for (int i=0; i<N-1; i++)
    {
        int a, b, c;
        cin>>a>>b>>c;
        E[a-1].push_back(b-1);
        C[a-1].push_back(c);
        E[b-1].push_back(a-1);
        C[b-1].push_back(c);
    }

    int Q, K;
    cin>>Q>>K;

    vector<long long> D(N, 1000000000000000000LL);
    priority_queue<pair<long long, int>> P;
    vector<bool> F(N);
    P.push(make_pair(0, K-1));
    D[K-1] = 0;

    while (!P.empty())
    {
        int p = P.top().second;
        P.pop();
        if (F[p])
            continue;
        F[p] = true;

        for (int i=0; i<(int)E[p].size(); i++)
            if (D[p] + C[p][i] < D[E[p][i]])
                D[E[p][i]] = D[p] + C[p][i],
                P.push(make_pair(-D[E[p][i]], E[p][i]));
    }

    for (int q=0; q<Q; q++)
    {
        int x, y;
        cin>>x>>y;
        cout<<D[x-1]+D[y-1]<<endl;
    }
}


Measured memory_bytes: 15980
#include<bits/stdc++.h>
using namespace std;
int A[500000+1], h;

int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

void maxHeap(int i){
  int l=left(i), r=right(i);
  int largest;
  
  if(l <= h && A[l] > A[i]) largest=l;
  else largest=i;

  if(r <= h && A[r] > A[largest]) largest=r;

  if(largest != i){
    swap(A[i], A[largest]);
    maxHeap(largest);
  }
}

  


int main(void){
  int i;
  
  scanf("%d", &h);
  for(i=1; i<=h; i++) scanf("%d", &A[i]);

  for(i=h/2; i>=1; i--) maxHeap(i);  

  for(i=1; i<=h; i++) printf(" %d", A[i]);
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 5176
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  rep(i, H) cin >> s.at(i);

  vector<int> dx(4), dy(4);
  dx = {-1, 0, 0, 1};
  dy = {0, -1, 1, 0};

  bool flag = true;
  rep(i, H) {
    rep(j, W) {
      if (s.at(i).at(j) == '#') {
        int cnt = 0;
        rep(k, 4) {
          int x = i + dx.at(k);
          int y = j + dy.at(k);
          if (x >= 0 && x < H && y >= 0 && y < W) {
            if (s.at(x).at(y) == '#') {
              ++cnt;
            }
          }
        }
        if (cnt == 0) {
          flag = false;
        }
      }
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
vector<int> G[100000];
P memo[100000];
P dfs(int x, int p, int r) {
  P m = P(r, x);
  for (int t : G[x]) if (t != p) m = max(m, dfs(t, x, r+1));
  return memo[x] = m;
}

vector<int> seq;
void dfs2(int x, int p) {
  int deg = 0;
  for (int t : G[x]) if (t != p && memo[x] != memo[t]) deg++;
  seq.pb(deg);

  for (int t : G[x]) if (t != p && memo[x] == memo[t]) dfs2(t, x);
}

vector<int> solve(vector<int> seq) {
  int n = 0;
  vector<int> ret;
  for (int deg : seq) {
    int id = n++;
    rep(_, deg) ret.pb(n++);
    ret.pb(id);
  }
  return ret;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N-1) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    G[u].pb(v);
    G[v].pb(u);
  }
  int u = dfs(0, -1, 0)._2;
  int v = dfs(u, -1, 0)._2;
  // u<->v
  dfs2(u, -1);
  int sum = seq.size();
  for (int x : seq) sum += x;
  if (sum != N) {
    cout << -1 << "\n";
  }
  else {
    vector<int> rev(seq); reverse(all(rev));
    vector<int> ans = min(solve(seq), solve(rev));
    for (int x : ans) cout << x+1 << " ";
    cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 20344
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;

int main(){
  int h,w;cin>>h>>w;
  int a;
  int ans=0;
  int c[10][10];
  rep(i,10){
    rep(j,10){
      cin>>c[i][j];
    }
  }
  int mins[10];
  rep(i,10){
    mins[i]=c[i][1];
  }
  rep(s,10){
  rep(i,10){
    if(i!=1){
      rep(j,10){
        mins[j]=min(mins[j],c[j][i]+mins[i]);
      }
    }
  }
  }
  
  rep(i,h){
    rep(j,w){
      cin>>a;
      if(a!=-1){
        ans+=mins[a];
      }
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N;
  cin >> N;
  vll d(N);
  rep(i, N) {
    cin >> d[i];
  }

  ll sum = 0;
  rep(i, N) {
    rep2(j, i + 1, N) {
      sum += d[i] * d[j];
    }
  }
  COUT(sum);
  return 0;
}

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

using namespace std;

#define fo(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define lli long long int
#define all(c) c.begin(),c.end()
#define lower(c) tolower(c)
#define upper(c) toupper(c)
#define max(c) *max_element(c.begin(),c.end())
#define min(c) *min_element(c.begin(),c.end())
#define len(c) c.size()
const int MOD = 1000000007;
const int MX = 2e5 + 5;
const int INF = 1e9 + 10;
const lli LINF = 1e18;

void solve() {
	long long a;
	cin >> a;
	cout << a*a+a+a*a*a;


}


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


    return 0;
}






Measured memory_bytes: 3656
n = int(input())
k = int(input())
x = list(map(int, input().split()))
ans = 0

for i in range(n):
    if x[i] >= k:
        ans += (x[i]-k)*2
    elif x[i] < k and k - x[i] < x[i]:
        ans += (k - x[i]) * 2
    else:
        ans += x[i]*2

print(ans)

Measured memory_bytes: 3064
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int N, M, Q;
    cin >> N >> M >> Q;


    vvi S(N, vi(N));

    rep(i, M)
    {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        reple(i, 0, l) S[i][r]++;
    }

    rep(i, N)
    {
        rep(j, N - 1)
        {
            S[i][j + 1] += S[i][j];
        }
    }

    rep(i, Q)
    {
        int p, q;
        cin >> p >> q;
        p--;
        q--;

        cout << S[p][q] << endl;
    }

    return 0;
}

Measured memory_bytes: 1920
import math
import itertools
#k,x = list(list(map(int, input().split())))
n = int(input())
a = list(list(map(int, input().split())))
b = list(list(map(int, input().split())))
ans = 0

for i in itertools.permutations(range(1,n+1,1),n):

    ans +=1
    if list(i) == a:
        ansa = ans
    if list(i) == b:
        ansb = ans


print(abs(ansa-ansb))

Measured memory_bytes: 74312
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(L[int(input())-1])

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	long a[110000]={0},b[110000]={0};
	long N,temp,times=0;
	cin>>N;
	for(int i=1;i<N+1;i++)
	cin>>a[i];
	temp=1;
	while(b[temp]!=1&&temp!=2)
	{
		times++;
		b[temp]=1;
		temp=a[temp];
	}
	if(temp==2)
	cout<<times;
	else cout<<0-1;
	
	
}


Measured memory_bytes: 1920
alpa = 'zabcdefghijklmnopqrstuvwxy'
N = int(input())
# for i in range(703, 730):
#     print((i-1)//26, i)
ans = []
while N >= 27:
    ans.append(alpa[N%26])
    N = (N-1)//26

ans.append(alpa[N%26])
ans.reverse()
print(*ans, sep='')


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <atcoder/all>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using namespace atcoder;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n, q;
  cin >> n >> q;
  fenwick_tree<ll> fw(n);
  rep(i, n) {
    int ai;
    cin >> ai;
    fw.add(i, ai);
  }

  rep(i, q) {
    int query;
    cin >> query;
    if (query == 0) {
      ll p, x;
      cin >> p >> x;
      fw.add(p, x);
    } else {
      int l, r;
      cin >> l >> r;
      cout << fw.sum(l, r) << endl;
    }
  }
}


Measured memory_bytes: 8216
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
      
      	cout<<n*n<<endl;

    }
  return 0;
}




Measured memory_bytes: 256
/*
	       ^  ^
			--

	Hello there!   __________    ___  __
	                |       |     |   /
	                |       |     |  /
	                |       |     | /
	                |_______|     |/
	                | \           |\
	                |  \          | \
	                |   \         |  \
	              __|    \________|   \__
*/

#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define f(x, n)             for(int x = 0; x < n; ++ x)
#define fr(x,n)             for(int x=1;x<=n;x++)
#define mp                  make_pair
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define pb                  push_back
#define eb                  emplace_back
#define pii 				pair<int,int>
#define pll 				pair<ll,ll>
#define F 					first
#define S 					second
#define inf 				1e18
#define MOD 				1000000007
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)

int32_t main()
{
	fast;
	int n,k;cin>>n>>k;
	int a[n];
	f(i,n){
		cin>>a[i];
	}
	vector<int> dp(n,INT_MAX);
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<=i+min(k,n);j++){
			dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
		}
	}
	cout<<dp[n-1];
}


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

using namespace std;

using ll = long long;

ll maxans = 1e18;

int main()
{
    int n;
    ll ans = 1;
    cin >> n;
    vector<ll> nums(n);
    for(auto& x : nums) { 
        cin >> x;
        if(!x) {
            cout << '0';
            return 0;
        }
    }
    for(int i = 0; i < n; i++) {
        if(maxans/ans < nums[i]) { cout << "-1"; return 0; }
        ans *= nums[i];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define se second
#define fi first
const int N=1e5 + 5;
int v[N];
int main(){

//	freopen("in.txt","r",stdin);

	int n;
	scanf("%d",&n);
	int a=0,b=0,c=0;
	for(int i=0;i < n;i++){
		scanf("%d",&v[i]);
		if(v[i] % 4 == 0) a++;
		else if(v[i] % 2 == 0) b++;
		else c++;
	}
	if (a>=c|| !c){
		puts("Yes");
		return 0;
	}
	if (a+1 ==c && !b){
		puts("Yes");
		return 0;
	}
	puts("No");

	return 0;
}


Measured memory_bytes: 640
N,Q = map(int,input().split())
dp = [0] * (N+2)
dp[2] = 1
ball = 1
for i in range(Q):
    a,b = map(int,input().split())
    dp[a],dp[b] = dp[b],dp[a]
    if ball == a:
        ball = b
    elif ball == b:
        ball = a
    dp[ball-1] |= 1
    dp[ball+1] |= 1
dp[ball] |= 1
print(sum(dp[1:-1]))

Measured memory_bytes: 4596
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#define INF 1000000007
using namespace std;
using P = pair<int, int>;
using ll = long long;
int main(){
    int n;
    cin>>n;
    int k1,k2;
    int k[214514];
    for(int i=0;i<n;i++)cin>>k[i];
    k1=k[0];
    k2=k[1];
    if(k1<k2)swap(k1, k2);
    for(int i=2;i<n;i++){
        int a=k[i];
        if(a>=k1){
            k2=k1;
            k1=a;
        }else if(a>=k2){
            k2=a;
        }
    }
    for(int i=0;i<n;i++){
        if(k[i]==k1)cout<<k2<<endl;
        else cout<<k1<<endl;
    }
    return 0;
}


Measured memory_bytes: 2432
[h,w] = [int(x) for x in input().split()]

if h == 1 or w == 1:
    print(1)

else:
    row1 = w//2 + w%2
    row2 = w//2

    total = (row1 * (h//2+h%2)) + (row2 * (h//2))

    print(total)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define ld long double
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rloop(i,a,b) for(ll i=a;i>b;i--)
const ll inf=1e9+7;

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

ll n,k;
cin>>n>>k;

ll a[n];
ll sum=0;
	loop(i,0,n)cin>>a[i];
	
	vector<ll>dp(k+1),new_dp(k+1);
	dp[0]=1;
	
	loop(i,1,n+1)
	{	
		sum=0;
		loop(j,0,k+1)
		{	
		sum+=(dp[j]+inf)%inf;
		sum=(sum+inf)%inf;
			if(a[i-1]>=j){
			
					
				
						new_dp[j]=sum;
			}
		
			else
			{
				
				sum-=(dp[j-a[i-1]-1]+inf);
				sum=(sum+inf)%inf;
				new_dp[j]=sum;	
			
				
			}
		
			
			
		}
	
		swap(dp,new_dp);
			
		
		
		
		
		
		
	}
	cout<<(dp[k]+inf)%inf;
	
	
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
#include<math.h>
using namespace std;

int main() {
	int x = 0, n, ans=0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'I') {
			x++; 
		}
		else
		{
			x--;
		}
		ans = max(ans, x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256