akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
    struct node*left;
    struct node *parent;
  int key;
};
  typedef struct node *Node;

Node root;

void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;


  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL )
    {
      y = x;
      if( z->key < x->key )
	{
	  x = x->left;
	}
      else
	{
	  x = x->right;
	}

    }
  z->parent = y;
  if( y == NIL )
    {
      root = z;
    }
  else
    {
      if( z->key < y->key )
	{
	  y->left = z;
	}
      else
	{
	  y->right = z;
	}
    }
}


void inoder(Node u)
{
  if( u != NIL )
    { 
  inoder(u->left);
  printf(" %d",u->key);
  inoder(u->right);
    }
}

void preoder(Node u)
{
  if( u!= NIL )
    {
  printf(" %d", u->key);
  preoder(u->left);
  preoder(u->right);
    }
}
    
    




int main()
{
  char com[20];
  int n,x,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s",com);
      if( com[0]=='i')
	{
	  scanf("%d",&x);
	  insert(x);
	}
      else if( com[0]=='p')
	{
	  inoder(root);
	  printf("\n");
	  preoder(root);
	  printf("\n");
	}
    }
  return 0;
}












	



Measured memory_bytes: 25300
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int H = scan.nextInt();
    int W = scan.nextInt();
    while(H != 0 || W != 0){
      StringBuilder sb = new StringBuilder();
      for(int i=0; i<W; i++ ){
        sb.append("#");
      }
      for(int j=0; j<H; j++){
        System.out.println(sb);
      }
      System.out.println("");
      H = scan.nextInt();
      W = scan.nextInt();
    }
    
  }
}

Measured memory_bytes: 27768
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,m;cin>>n>>m;
  vector<int> a(n);rep(i,n)cin>>a[i];
  sort(all(a));
  int ans = 0;
  rep(i,n){
    if(m - a[i] >= 0){
      ans++;
      m -= a[i];
    }else{
      m = 0;
      break;
    }
  }
  if(m)ans--;
  print(ans);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iomanip>
#define int long long
#define ll long long
#define FOR(P,Q) for(P=0;P<Q;P++)
#define FORR(P,Q) for(P=1;P<=Q;P++)
#define FORS(i,s) for(i=0;s[i]!='\0';i++)
#define pb push_back
using namespace std;

/*std::cout << std::fixed;
    std::cout << std::setprecision(14);
    std::cout << d;
*/
    
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  #ifndef ONLINE_JUDGE
	freopen("error.txt","w",stderr);
	#endif

	int a,b;
	cin>>a>>b;
	if(a>8||b>8)
		cout<<":(";
	else 
		cout<<"Yay!";
		
 return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderCs
{
    class Program
    {
        static void Main()
        {

            var str = Console.ReadLine();
            Console.WriteLine(str[2] == str[3] && str[4] == str[5] ? "Yes" : "No");

        }

    }
}


Measured memory_bytes: 13140
#include<iostream>
#include <algorithm>
#include <numeric>
#define rep(i,n) for(int i=1;i<=n;i++)
typedef long long int llint;
using namespace std;


int main() {
	int n,c;
  	llint ans=0;
	cin >> n;
	rep(i,n){
    	rep(j,n){
        	rep(k,n){
            	c = gcd(i,j);
                // cout << gcd(c,k) << c << "\n";
              	ans = gcd(c,k) + ans ;
            }
        }
    }
	cout << ans;   
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    using P = pair<pair<ll,ll>,int>;
    vector<P> vp(n);
    rep(i,n) {
        cin >> a[i] >> b[i];
        vp[i] = {{a[i]+b[i],a[i]}, i};
    }
    sort(all(vp),greater<P>());
    ll res = 0;
    rep(i,n) {
        int id = vp[i].second;
        if (i%2 == 0) {
            res += a[id];
        } else {
            res -= b[id];
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4096
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	priority_queue<P> pq;
	rep(i,n){
		ll a;
		cin >> a;
		pq.push(P(a, 1));
	}
	rep(i,m){
		ll b, c;
		cin >> b >> c;
		pq.push(P(c, b));
	}
	ll ans = 0, cnt = 0;
	while(cnt < n && !pq.empty()){
		P p = pq.top();
		pq.pop();
		if(cnt+p.second >= n){
			ans += p.first * (n - cnt);
			cnt = n;
		}
		else{
			ans += p.first * p.second;
			cnt += p.second;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define endl "\n"
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)                   
using namespace std;                            
                                                
void yes() {cout << "YES" << endl;}                                               
void no() {cout << "NO" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const long long INF = 8e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7;

void solve() {
    long long x; cin >> x;
    long long k, d; cin >> k >> d;
    long long a = abs(x);
    long long r = a % d;
    long long s1 = ((a - r) / d);
    long long ans = INF;
    if (s1 <= k) {
        if ((k - s1) & 1) {
            ans = min(ans, d - r);
        } else {
            ans = min(ans, r);
        }
    } else {
        ans = min(ans, a - k * d);
    }
    cout << ans << endl;
}

int main() {
    jonathan; 
    livingston;
    bool tests = 0;
    int t = 1;
    if (tests) cin >> t;
    for (int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3644
import itertools
def f(s):
 for x,y,z in itertools.product('+-*',repeat=3):
  for a,b,c,d in itertools.permutations(s):
   yield f"({a} {x} {b}) {y} ({c} {z} {d})"
   yield f"(({a} {x} {b}) {y} {c}) {z} {d}"
   yield f"{a} {x} ({b} {y} ({c} {z} {d}))"
   yield f"({a} {x} ({b} {y} {c})) {z} {d}"
   yield f"{a} {x} (({b} {y} {c}) {z} {d})"
for e in iter(input,'0 0 0 0'):
 s=list(map(int,e.split()));a=0
 for m in f(s):
  if eval(m)==10:a='('+m+')';break
 print(a)


Measured memory_bytes: 5660
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<char> d(k);
    rep(i, k)cin >> d[i];

    for(int p = n; p < 100000; p++){
        string s = to_string(p);
        bool like = true;
        rep(i, s.size()){
            rep(j, k){
                if(s[i] == d[j])like = false;
            }
        }
        if(like){
            cout << s << endl;
            return 0;
        }
    }
    
}

Measured memory_bytes: 256
n, m = [int(item) for item in input().split()]
ab = [[int(item) for item in input().split()] for _ in range(m)]
edge = [[] for _ in range(n)] 
for a, b in ab:
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

ans = 0
def dfs(visited, v):
    global ans
    nvisited = visited[:]
    nvisited.append(v)
    if len(nvisited) == n:
        ans += 1
    for item in edge[v]:
        if item not in nvisited:
            dfs(nvisited, item) 

dfs([], 0)
print(ans)

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

int main()
{
    int n,i,j,c;
    long long int ans=0;
    cin>>n;
    for(i=1;i<n;i++)
    {
        for(j=1;j<n;j++)
        {
            c=n-i*j;
            if(c>0)
            {
                ans++;
            }
            else
            {
                break;
            }
        }
    }
    cout<<ans<<endl;

}


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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

class UnionFind {
protected:
  int size;
  vector<int> _leader;
  vector<int> _rank;
  
public:
  UnionFind(int s);
  int leader(int i);
  int merge(int i, int j);
};

UnionFind::UnionFind(int s) {
  size = s;
  _leader = vector<int>(size);
  for (int i = 0; i < size; i++) { _leader.at(i) = i; }
  _rank = vector<int>(size, 1);
}

int UnionFind::leader(int i) {
  int cur = i;
  int nxt = _leader.at(cur);
  vector<int> seen;
  while (cur != nxt) {
    seen.push_back(cur);
    cur = nxt;
    nxt = _leader.at(cur);
  }
  for (auto j : seen) _leader.at(j) = cur;
  return cur;
}

int UnionFind::merge(int i0, int j0) {
  int li = leader(i0);
  int lj = leader(j0);
  if (li == lj) return li;
  int ri = _rank.at(li);
  int rj = _rank.at(lj);
  if      (ri < rj)  return _leader.at(li) = lj;
  else if (ri > rj)  return _leader.at(lj) = li;
  else {
    (_rank.at(lj))++;
    return _leader.at(li) = lj;
  }
}

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  ll N, M, Q; cin >> N >> M >> Q;
  vector<int> A(Q), B(Q), C(Q);
  for (int i = 0; i < Q; i++) cin >> A.at(i) >> B.at(i) >> C.at(i);

  if (M == N-1) {
    if (all_of(C.begin(), C.end(), [&](int c){return c == 0;})) {
      cout << "Yes\n";
      return 0;
    }else {
      cout << "No\n";
      return 0;
    }
  }

  UnionFind uf(N);
  for (int i = 0; i < Q; i++) {
    if (C.at(i) == 0) uf.merge(A.at(i), B.at(i));
  }
  ll ncc = 0;
  for (int i = 0; i < N; i++) if (uf.leader(i) == i) ncc++;
  if ((ll)M <= (ll)N + (ll)ncc * (ll)(ncc - 3LL) / 2LL) {
    for (int i = 0; i < Q; i++) {
      if (C.at(i) == 1 && uf.leader(A.at(i)) == uf.leader(B.at(i))) {
	cout << "No\n";
	return 0;
      }
    }
    cout << "Yes\n";
  }else {
    cout << "No\n";
  }

  return 0;
}



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

using namespace std;

const int vy[] = {-1, 0, 1, 0};
const int vx[] = {0, 1, 0, -1};


void bfs(vector< int > &s, int idx)
{

  queue< pair< int, int > > que;
  queue< int > beet;
  que.emplace(idx, -1);
  vector< int > bomb(16, 114514);
  beet.emplace(0);

  while(!que.empty()) {
    auto p = que.front();
    que.pop();

    int latte = beet.front();
    beet.pop();
    int xx = p.first % 4, yy = p.first / 4;

    if(s[p.first] <= 4) {
      ++s[p.first];
      if(s[p.first] == 5) {
        bomb[p.first] = latte;
        for(int i = 0; i < 4; i++) {
          int nx = xx + vx[i], ny = yy + vy[i];
          if(nx < 0 || ny < 0 || nx >= 4 || ny >= 4) continue;
          que.emplace(ny * 4 + nx, i);
          beet.emplace(latte + 1);
        }
      }
    } else if(latte != bomb[p.first]) {
      int nx = xx + vx[p.second], ny = yy + vy[p.second];
      if(nx < 0 || ny < 0 || nx >= 4 || ny >= 4) continue;
      que.emplace(ny * 4 + nx, p.second);
      beet.emplace(latte + 1);
    }
  }

}

int main()
{
  int N;
  vector< int > vec(16);

  for(int i = 0; i < 16; i++) {
    cin >> vec[i];
    if(vec[i] == 0) vec[i] = 5;
  }

  map< vector< int >, int > dp;
  queue< vector< int > > que;
  dp[vec] = 0;
  que.emplace(vec);

  while(!que.empty()) {
    auto p = que.front();
    int cost = dp[p];
    que.pop();
    if(count(begin(p), end(p), 5) == 16) {
      cout << cost << endl;
      return (0);
    }

    if(cost == 5) {
      continue;
    }

    for(int i = 0; i < 16; i++) {
      if(p[i] == 5) continue;
      auto q = p;
      bfs(q, i);
      if(dp.count(q)) continue;
      dp[q] = cost + 1;
      que.emplace(q);
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 8248
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int id_cnt=0;

struct node{
	node *left,*right;
	int n,id;
	node(node *left,node *right,int id):left(left),right(right),n(-1),id(id){}
	node(int n,int id):n(n),left(NULL),right(NULL),id(id){}

	vi search(vvi &masks,string &pattern){
		if(n!=-1){
			return masks[n];
		}
		vi l_mask=left->search(masks,pattern);
		vi r_mask=right->search(masks,pattern);
		vi ret(4);
		switch(pattern[id]){
		case 'A':
			REP(i,4){
				ret[i]=l_mask[i]&r_mask[i];
			}
			break;
		case 'O':
			REP(i,4){
				ret[i]=l_mask[i]|r_mask[i];
			}
			break;
		case 'X':
			REP(i,4){
				ret[i]=l_mask[i]^r_mask[i];
			}
			break;
		}
		return ret;
	}

	void make_initial_pattern(string &pattern){
		if(n!=-1){
			pattern[id]='.';
		}else{
			pattern[id]='A';
		}
		if(left){
			left->make_initial_pattern(pattern);
		}
		if(right){
			right->make_initial_pattern(pattern);
		}
	}
};


node *read(string &s, int &p){
	switch(s[p]){
	case '(':
		{
		p++;
		node *left=read(s,p);
		assert(s[p]==' ');
		p++;
		node *right=read(s,p);
		assert(s[p]==')');
		p++;
		return new node(left,right,id_cnt++);
		}
	default:
		assert(isdigit(s[p]));
		return new node(s[p++]-'0'-1,id_cnt++);
	}
}

bool increment(string &pattern,int n){
	if(n==pattern.size()){
		return false;
	}
	switch(pattern[n]){
	case 'A':
		pattern[n]='O';break;
	case 'O':
		pattern[n]='X';break;
	case 'X':
		pattern[n]='A';
		if(!increment(pattern,n+1)){
			return false;	
		}
		break;
	default:
		if(!increment(pattern,n+1)){
			return false;	
		}
	}
	return true;
}

int main(){
	string s;
	while(getline(cin,s),s!="END"){
		int p=0;
		node *root=read(s,p);
		int n;
		cin>>n;
		vvi masks(n);
		REP(i,n){
			REP(j,4){
				int b;
				cin>>b;
				masks[i].push_back(b);
			}
		}
		string pattern(id_cnt,' ');
		root->make_initial_pattern(pattern);
		int ans=0;
		while(1){
			vi m=root->search(masks,pattern);
			bool flag=true;
			REP(i,4){
				if(m[i]==0){
					flag=false;
					break;
				}
			}
			if(flag){
				ans++;
			}
			if(!increment(pattern,0)){
				break;
			}
		}
		cout<<ans<<endl;
		getline(cin,s);
	}
}

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

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

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

    OP(min(b, a * n));

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.array, std.algorithm;

void main() {
   auto a = readln.split.map!(to!int);
   if (a[0] >= a[1]) {
      writeln("No"); return;
   }
   if (a[1] >= a[2]) {
      writeln("No"); return;
   }
   writeln("Yes");
}

Measured memory_bytes: 2468
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[1000007]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
*/
using namespace std;
signed main(){
  fast;
  //usefile;
  //test
  {
    string s;
    cin>>s;
    deque<char> dq;
    for(auto i:s){
      dq.pb(i);
    }
    bool flag=0;
    int t;
    cin>>t;
    while(t--){
      int q;
      cin>>q;
      if(q==1){
        flag^=1;
      }
      else{
        int f;
        cin>>f;
        char ch;
        cin>>ch;
        if(f==1){
          if(!flag)
            dq.push_front(ch);
          else
          {
            dq.pb(ch);
          }          
        }
        else{
           if(flag)
            dq.push_front(ch);
          else
          {
            dq.pb(ch);
          }  
        }
      }
    }
    if(flag)
      while(dq.size()){
        cout<<dq.back();
        dq.pop_back();
      }
    else
    {
      while(dq.size()){
        cout<<dq.front();
        dq.pop_front();
      }
    }
    
  }
  //time("");
  return 0;
}

Measured memory_bytes: 976
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define lli long long int
#define llu long long unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,s,e) for(i=s; i<e; i++)
#define mod 1000000007
#define F first
#define S second
#define plli pair<lli,lli>
#define pqlli priority_queue<lli>
#define test(t) cin>>t; while(t--)
using namespace std;


lli dfs(map<lli, vector<lli> > &m, lli n, map<plli, lli> &color, lli i, lli current, lli mark[], lli some[], lli degree)
{
	mark[i] = 1;lli j, c = 0;
	for(j = 0; j<m[i].size(); j++)
	{
		if(mark[m[i][j]] == 0){
		color[mp(i, m[i][j])] = some[(current + c)%degree];
		color[mp(m[i][j], i)] = some[(current + c)%degree];
	//	if(mark[m[i][j]] == 0)
		dfs(m, n, color, m[i][j], (current + c + 1)%degree, mark, some, degree);
		c++;
	}
	}
}
int main()
{
	lli n, i;
	cin>>n;
	map<lli,vector<lli> > m;
	vector<plli> edges;
	lli cnt[n+1], degree = 0;
	lli mark[n+1];
	memset(mark, 0, sizeof(mark));
	memset(cnt, 0, sizeof(cnt));
	for(i = 0; i<n-1; i++)
	{
		lli one,two;
		
		cin>>one>>two;
		edges.pb(mp(one,two));
		m[one].pb(two);
		m[two].pb(one);
		cnt[one]++;
		cnt[two]++;
		degree = max(degree, cnt[one]);
		degree = max(degree, cnt[two]);
	}
	
	lli colors[degree];
	for(lli i = 0; i<degree; i++)
	colors[i] = i+1;
	
	map<pair<lli,lli>, lli> color;
	
	dfs(m, n, color, 1, 0, mark, colors, degree);
	
	cout<<degree<<endl;
	for(i = 0; i<n-1; i++)
	cout<<color[edges[i]]<<endl;
}


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

int main() {
	int n, r, p, c, i, ans;
	
	while (cin >> n  && cin >> r) {
		int Deck[51];

		if (n == 0 && r == 0) {
			break;
		}

		for (i = 0; i < n; i++) {
			Deck[i] = n-i;
		}

		for (i = 0; i < r; i++) {
			cin >> p; cin >> c;

			rotate(Deck, Deck + p - 1, Deck + p + c - 1);
		}

		cout << Deck[0] << endl;
	}
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n,m,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        sum+=i;
        if(sum>=n){m=i;break;}
    }
    for(int i=0;i<m;i++){
        if(i+1!=sum-n)cout<<i+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x

#ABC145-E
def kdp(s,K):#s(str)以下の非負整数で条件をK桁満たすものの個数
    #K: 条件を満たすべき桁数 O(桁数*条件を満たすべき桁数*10)
    
    #mod = 1000000007
    keta=len(s)
    dp=[[[0,0] for _ in range(K+1)] for _ in range(keta+1)]
    #dp[i][j][k]前からi桁目まで決め、j個の条件を満たす桁を含み、k=1:i文字目まで一致 k=0:対象の数以下

    dp[0][0][0]=1
    for i in range(0,keta):
        ni=i+1
        nd=int(s[i])
        for j in range(0,K+1):
            for k in range(0,2):  
                for d in range(10): 
                    nj=j
                    nk=k
                    if d!=0:#この辺に条件
                        nj+=1
                    if nj>K:continue
                    if k==0:
                        if d>nd:
                            break
                        elif d<nd:
                            nk=1
                    dp[ni][nj][nk]+=dp[i][j][k]

    ans=dp[keta][K][1]+dp[keta][K][0]
    #与えられた数未満で条件を満たすもの+与えられた数が条件を満たす場合1
    print(ans)

if __name__ == "__main__":
    s = input()
    K= int(input())#条件を満たすべき桁数
    kdp(s,K)

Measured memory_bytes: 40304
using System;
using System.Linq;

class Program
{
  static void Main(string[] args)
  {
    var cs = Console.ReadLine().ToCharArray();

    var min = Int32.MaxValue;
    for (int i = 0; i < cs.Count() - 2; i++)
    {
      var s = new string(new char[] { cs[i], cs[i + 1], cs[i + 2] });
      var n = Int32.Parse(s);
      var diff = Math.Abs(753 - n);
      if (diff < min)
      {
        min = diff;
      }
    }

    Console.WriteLine(min);
  }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(2);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 15;
const ll bits = 63;
const ll mod = 1e9+7;
const ld pi = 3.14159265358979323846;

ll cnt(ll n){
    ll ans=0;

    while(n%10==0){
        ans++;
        n/=10;
    }

    return ans;

}


int main(){
    // FASTIO;

    ll n;
    cin>>n;

    if(n%2){
        cout<<0<<"\n";
    }else{
        ll cntr=10;
        ll ans=0;
        ll fact = 10;

        // while(cntr<=n){
        //     ans+=n/cntr;

        //     if(cntr==n){
        //         break;
        //     }
        //     cntr*=fact;
        //     cout<<cntr<<"\n";
            
        // }

        cntr=10LL;
        fact=5;
        while(cntr<=n){
            ans+=n/cntr;

            if(cntr==n){
                break;
            }
            cntr*=fact;
            // cout<<cntr<<"\n";
            
        }

        cout<<" "<<ans<<"\n";
    }

    


    

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
//setprecision(12)
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
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; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<ll> a(n);
    map<ll,ll> m;
    rep(i,n) {
        cin >> a[i];
        m[a[i]]++;
    }
    ll ans = 0;

    for(auto val : m) {
        ans += val.second*(val.second-1)/2;
    }

    rep(i,n) {
        int num = m[a[i]];
        cout << ans - num + 1 << endl;
    }


    return 0;
}

Measured memory_bytes: 11136
import math


def ncr(n, r):
    f = math.factorial
    return f(n) // f(r) // f(n - r)

n, p = [int(i) for i in input().split()]
nbiss = [int(i) for i in input().split()]
ret = 0
num = [0, 0]
for x in nbiss:
    num[x % 2] += 1
if p > num[1]:
    print(0)
else:
    for i in range(p, num[1]+1, 2):
        ret += ncr(num[1], i)
    ret *= (2 ** num[0])
    print(ret)


Measured memory_bytes: 3064
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

_ = input()
st = input().strip()
total = 0
result = [0]

for i in st:
    if (i == 'I'):
        total += 1
        result.append(total)
    else:
        total -= 1
        result.append(total)
print (max(result))

Measured memory_bytes: 3064
main(){float d,e,f,g,h,i,m,n,p;for(;~scanf("%f%f%f%f%f%f%f%f",&d,&e,&f,&g,&h,&i,&m,&n);puts(((f-d)*(n-e)-(m-d)*(g-e))*p>0&&p*((d-h)*(n-i)-(m-h)*(e-i))>0?"YES":"NO"))p=(h-f)*(n-g)-(m-f)*(i-g);return 0;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const ll INF=1e18;


int main() {
  ll n,d,x,y,ans=0;
  long double w;
  cin >> n >> d;
  rep(i,n){
    cin >> x >> y;
    w = sqrt(pow(x,2)+pow(y,2));
    if(w <= d) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
//Shivam gupta (Codeforces handle : shivam_1999)

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define ll long long
#define ld long double
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef pair<long long, long long> pii;
typedef vector<pair<long long, long long>> vpii;
typedef map<long long, long long> mii;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define sorta(x) sort(x.begin(),x.end())
#define sortd(v) sort(all(v), greater<ll>())
#define el cout << endl;
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define cpresent(container, element) (find(all(container), element) != container.end())
#define deb(x) cout << #x << x << endl;
#define fl(i,n) for(ll i=0;i<n;i++)
#define fls(i,x,n) for(ll i=x;i<n;i++)
#define flr(i,n)  for(ll i=n-1;i>=0;i--)
#define fla(i,v)  for(auto i:v)    
#define in(v) for(auto &i:v){cin>>i;}
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define tt    \
    int T;    \
    cin >> T; \
    while (T--)


int main()
{   fast
    ll n;
    cin >> n;
    vi v(n);
    in(v)
    vi dp(n, 0);
    dp[1] = abs(v[1] - v[0]);
    fls(i,2,n){
        dp[i] = min(dp[i - 1] + abs(v[i] - v[i - 1]), dp[i - 2] + abs(v[i] - v[i - 2]));
    }
    cout << dp[n - 1];
}

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

using namespace std; 

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

	int n;
	cin >> n;

	for(int i = 1; i <= 9; i++) {
		if(n % i == 0 and n/i < 10) {
			cout << "Yes\n";
			return 0;
		}
	}

	cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
N=int(input())
S={}
for n in range(N):
  s=input()
  S[s]=S.get(s,0)+1

maxS=max(S.values())
S={k:v for k, v in S.items() if v==maxS}
S=sorted(S.items(), key=lambda x:(-x[1],x[0]))
for k,cnt in S:
  print(k)


Measured memory_bytes: 67208
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N;
    cin >> N;
    vector<int>L(N*2);
    for(int i = 0; i < N*2; i++) {
        cin >> L[i];
    }
    sort(L.begin(),L.end());
    int res = 0;
    for(int i = 0; i < N*2; i+=2) {
        res+=L[i];
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

ll n, a[2000], dp[2000][2000];

ll search(ll num, ll counter) {
  if (dp[num][counter] > -1) return dp[num][counter];
  ll d1 = a[num], d2 = a[(num + counter - 1) % n];
  ll n1 = (num + 1) % n;
  if ((n - counter) % 2 == 0) { // me
    return dp[num][counter] = max(d1 + search(n1, counter - 1), d2 + search(num, counter - 1));
  }
  if (d1 > d2) return dp[num][counter] = search(n1, counter - 1);
  return dp[num][counter] = search(num, counter - 1);
}

int main() {
  scanf("%lld", &n);
  for (ll i = 0; i < n; i++) for (ll j = 0; j < n; j++) dp[i][j] = -1;
  for (ll i = 0; i < n; i++) scanf("%lld", &a[i]), dp[i][1] = n % 2 == 0 ? 0 : a[i];
  ll ans = search(0, n - 1) + a[n - 1];
  for (ll i = 0; i < n - 1; i++) ans = max(ans, search(i + 1, n - 1) + a[i]);
  printf("%lld\n", ans);
}



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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int r, d, x;
  cin >> r >> d >> x;

  int ans;
  for (int i = 0; i < 10; i++) {
    ans = r * x - d;
    cout << ans << endl;
    x = ans;
  }

  return 0;
}


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

if N == 0:
  print("0")
  exit()

res = ""
while N != 1:
  if N % 2 == 0:
    res += "0"
    N = N / (-2)
  else:
    res += "1"
    N = (N -1) / (-2)
res += "1"
print(res[::-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll rui(ll a,ll b){
  ll ans=1;
  while(b>0){
    if(b&1) ans = ans*a%mod;
    a = a*a%mod;
    b/=2;
  }
  return ans;
}
ll comb(ll a,ll b){
    ll ans=1;
    for(ll i=a;i>a-b;i--){
        ans=ans*i%mod;
    }
    for(ll i=1;i<=b;i++){
        ans=(ans*rui(i,mod-2))%mod;
    }
    return ans;
}

int main() {
  ll n,a,b,sum,nca,ncb;
  cin>>n>>a>>b;
  sum = rui(2,n)-1;
  nca = comb(n,a);
  ncb = comb(n,b);
  cout<<(mod+mod+sum-nca-ncb) % mod;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

int main()
{
    fastio;
    int A, B;
    string S;
    cin >> A >> B >> S;

    auto postal_code_str = S.substr(0, A) + S.substr(A + 1, B);

    if (postal_code_str.find_first_not_of("0123456789") == string::npos &&
        S[A] == '-')
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define sh cin.tie(0); cin.sync_with_stdio(0); cout.tie(0);
#define FILE freopen("test.in", "r", stdin);
#define vprint(v) for (int ii = 0; ii < v.size(); ii++){cout << v[ii] << " ";}
#define debugv(v) if (v.size() != 0) {cout << "[ "; for (int __ = 0; __ < (int)(v.size()) - 1; __++){cout << v[__] << ", ";} cout << v[(int)(v.size()) - 1] << " ]" << endl;} else {cout << "[]" << endl;}
#define debug cout << "-----------------------------------------------" << endl;
#define print1(a) cout << "{ " << a << " }" << endl;
#define print2(a, b) cout << "{ " << a << ", " << b << " }" << endl;
#define print3(a, b, c) cout << "{ " << a << ", " << b << ", " << c << " }" << endl;
#define print4(a, b, c, d) cout << "{ " << a << ", " << b << ", " << c << ", " << d << " }" << endl;
using namespace std;
#define int long long
const int INF = 1e9 + 228;
const int MAXN = 1e5 + 228;
map<string, int> mapa;
signed main()
{
#ifdef LOCAL
    FILE;
#endif
    sh;
	string a, b;
	cin >> a >> b;
	int n, m;
	cin >> n >> m;
	mapa[a] = n;
	mapa[b] = m;
	string u;
	cin >> u;
	mapa[u]--;
	cout << mapa[a] << ' ' << mapa[b] << endl;    
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
def main():
    N = int(input())
    D = Counter([int(_) for _ in input().split()])
    M = int(input())
    T = Counter([int(_) for _ in input().split()])
    
    for t in T.keys():
        if D[t] < T[t]:
            print('NO')
            break
    else:
      print('YES')
    return

if __name__ == '__main__':
    main()
    

Measured memory_bytes: 55384
n,m = map(int, input().split())

path_dict = {n_i:[] for n_i in range(1, n+1)}

for _ in range(m):
  a, b = map(int, input().split())
  path_dict[a].append(b)
  path_dict[b].append(a)
  
for n_i in range(1, n+1):
  print(len(path_dict[n_i]))

Measured memory_bytes: 3064
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int a;
    cin>>a;
    vector<int> vec(a);
    vector<int> mvec(a);
    rep(i,a){
        cin>>vec.at(i);
    }
    rep(i,a){
        mvec.at(vec.at(i)-1)=i+1;
    }
    rep(i,a){
        cout<<mvec.at(i)<<endl;
    }
}



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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (true)
    {
        c -= b;
        if (a <= 0)
        {
            cout << "No" << endl;
            return 0;
        }
        a -= d;
        if (c <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n,mi=10000000000,ma=-10000000000,r;
  cin >> n;
  for(int i=0;i<n;i++){
    cin>>r;
    ma=max(ma,r-mi);
    mi=min(mi,r);
  }
  cout << ma << endl;
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int sum = 0;

    for (int i = 0; i < n; i++) {
      sum += sc.nextInt();
    }

    System.out.println(sum - n);

  }
}

Measured memory_bytes: 40776
#include <iostream>

using namespace std;

int main(){
    int card[3][3];
    for(auto&& i : card){
        for(auto&& j : i){
            cin >> j;
        }
    }
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int num;
        cin >> num;
        for(auto&& j : card){
            for(auto&& k : j){
                if(k ==  num){
                    k = -1;
                }
            }
        }
    }
    for(int i = 0; i < 3; i++){
        if(card[i][0] == -1 && card[i][1] == -1 && card[i][2] == -1){
            cout << "Yes\n";
            return 0;
        }
        if(card[0][i] == -1 && card[1][i] == -1 && card[2][i] == -1){
            cout << "Yes\n";
            return 0;
        }
    }
    if(card[0][0] == -1 && card[1][1] == -1 && card[2][2] == -1){
        cout << "Yes\n";
        return 0;
    }
    if(card[0][2] == -1 && card[1][1] == -1 && card[2][0] == -1){
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

struct Edge{
	int from, to;
	ll cost;
	Edge(int from, int to, ll cost) : from(from), to(to), cost(cost){}
};

int n, m;

vector<bool> ng;

vector<Edge> es;
vector<ll> dist;
void bellman_ford(int s){
	dist[s] = 0;
	for(int i = 0; i < n - 1; ++i){
		for(auto e : es){
			if(dist[e.from] == LINF)continue;
			dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
		}
	}

	ng.assign(n, false);
	for(int i = 0; i < n; ++i){
		for(auto e : es){
			if(dist[e.from] == LINF)continue;
			if(dist[e.from] + e.cost < dist[e.to]){
				dist[e.to] = dist[e.from] + e.cost;
				ng[e.to] = true;
			}

			if(ng[e.from])ng[e.to] = true;
		}
	}
}

int main(){
  int s;
  cin >> n >> m;
  for(int i = 0; i < m; ++i){
  	int a, b;
  	ll c;
  	cin >> a >> b >> c;
  	--a;
  	--b;
  	c = -c;
  	es.push_back(Edge(a, b, c));
  }

  dist.assign(n, LINF);
  bellman_ford(0);
  if(ng[n - 1]){
  	cout << "inf" << endl;
  	return 0;
  }
  cout << -dist[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from functools import lru_cache


sys.setrecursionlimit(500000)


@lru_cache(maxsize=None)
def rec(n):
    if n == 0:
        return 0
    res = n
    i = 1
    while i <= n:
        res = min(res, rec(n - i) + 1)
        i *= 6
    i = 9
    while i <= n:
        res = min(res, rec(n - i) + 1)
        i *= 9
    return res


N = int(input())
print(rec(N))




Measured memory_bytes: 128508
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int main(void) {
  ll H, W;
  cin >> H >> W;
  vector<string> A(H);
  REP(i, 0, H) cin >> A[i];

  vector<vector<ll>> dp(H, vector<ll>(W, 0));
  dp[0][0] = 1;

  REP(i, 0, H) REP(j, 0, W) if (A[i][j] == '.') {
    if (i + 1 < H && A[i + 1][j] == '.') {
      dp[i + 1][j] += dp[i][j];
      dp[i + 1][j] %= MOD;
    }
    if (j + 1 < W && A[i][j + 1] == '.') {
      dp[i][j + 1] += dp[i][j];
      dp[i][j + 1] %= MOD;
    }
  }

  cout << dp[H - 1][W - 1] << endl;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
const int inf = 1000000000;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338; // double PI = 4*atan(1);

int n,a[3][3], b[10];
bool appear[3][3];	 

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	//ifstream cin (".in");
	//ofstream cout (".out");
   string a,b;
   cin >> a >> b;
   int suma = stoi(a+b);
   for(int i=1; i<1000; i++){
   	if(i*i == suma){
   	     cout << "Yes\n";
   	     return 0; 
   	}
   }
   cout << "No\n";
   return 0;
}





Measured memory_bytes: 3620
#include <iostream>
#include <map>

int f( int n )
{
	if ( n % 2 )
	{
		return ( 3 * n + 1 );
	}
	else
	{
		return ( n / 2 );
	}
}

int main()
{
	int s;
	std::cin >> s;

	std::map<int, int> m;
	m[s]++;

	int tmp = s;
	long counter = 1;
	while ( 1 )
	{
		tmp = f( tmp );
		if ( m[tmp] != 0 )
		{
			std::cout << counter + 1 << std::endl;
			break;
		}
		else
		{
			m[tmp]++;
			counter++;
		}
	}

	return ( 0 );
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main() { 
  int n, w, a[31], ai, bi;  
  cin >> w >> n;
  for(int i=1; i<=w; i++) {
    a[i] = i;
  } 
  for(int i=0; i<n; i++) { 
    scanf("%d%*c%d",&ai, &bi); 
    swap(a[ai],a[bi]); 
  } 
  for(int i=1; i<=w; i++) { 
    cout << a[i] << endl; 
  }  
  return 0;
}


Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#define ll long long
const int maxn = 100005;
using namespace std;

main()
{
    int N;
    scanf("%d",&N);
    int a;
    int i;
    int str[maxn] = {0};
    int max;
    for(i = 0;i < N;i++)
    {
        scanf("%d",&a);
        str[a]++;
        str[a+1]++;
        str[a-1]++;
    }
        max = str[0];
        for(i = 0; i < maxn; i++)
            if(max < str[i])
                max = str[i];
    printf("%d\n",max);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  string S;
  cin >> S;
  vector <int> s(4);
  for (int i = 0; i < 4; i++) {
	  s[i] = S[i];
	}
  sort(s.begin(), s.end());
  if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
	  cout << "Yes" << endl;
	}
  else {
	  cout << "No" << endl;
	}
  return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;

int MOD = 1e9+7;

//ll po(ll b, ll p){ return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD;}
// ll pomd(ll a, ll k, ll md) { ll p; if (k == 0){ return 1; } p = pomd(a, k / 2, md); p = p * p % md; if (k % 2){ p = p * a % md; } return p; }
// counting divsrs: vi arr(N); for(int i{1}; i<N; ++i) for(int j=i; j<N; j+=i) d[j]++;

#define mp make_pair
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)

void setIO(string name = ""){
    freopen((name+".in").c_str(), "r", stdin); 
    freopen((name+".out").c_str(), "w", stdout);
}	

int calc_cost(vector<int> arr, int choice) {
    int ans = 0;
    for (int num : arr) {
        ans += (num - choice) * (num - choice);
    }
    return ans;
}

int main(){
 	ios_base::sync_with_stdio(0); cin.tie(0); 
	// setIO();
     int N;
    scanf("%d", &N);
    vector<int> arr(N);
    int total = 0;
    for (int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
        total += arr[i];
    }
    
    int avg = total / N;
  
    int ans = min({calc_cost(arr, avg-1), calc_cost(arr, avg), calc_cost(arr, avg+1)});
    
    printf("%d\n", ans);
	
	return 0;
}	





Measured memory_bytes: 3796
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n,q; cin>>n>>q;
  Graph g(n);
  int c[n],s[n];
  rep(i,n) s[i]=-1;
  rep(i,n) c[i]=0;
  rep(i,n-1){
    int a,b; cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  rep(i,q){
    int p,x; cin>>p>>x;
    p--;
    c[p]+=x;
  }
  //rep(i,n) cout<<c[i]<<" ";
  //cout<<endl;
  stack<int> p;
  p.push(0);
  s[0]=c[0];
  while(!p.empty()){
    int y=p.top(); p.pop();
    for(auto x:g[y]){
      if(s[x]!=-1) continue;
      p.push(x);
      s[x]=s[y]+c[x];
      //cout<<s[x]<<endl;
    }
  }
  rep(i,n){
    if(i!=n-1) cout<<s[i]<<" ";
    else cout<<s[i];
  }
}


Measured memory_bytes: 17356
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,l,r) for (ll i = (ll)l; i < (ll)(r); i++)

int main(){
  ll N,K; cin >> N >> K;
  vector<ll> v(N);
  rep(i,0,N) cin >> v[i];
  sort(v.begin(),v.end());
  ll sum = 0;
  rep(i,0,K) sum += v[i];
  cout << sum << endl;
}

Measured memory_bytes: 3604
fn main() {
    let n = input();
    println!("{}", solve(n));
}

fn input() -> usize {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let n: usize = buf.parse().unwrap();
    n
}

fn solve(n: usize) -> String {
    let l = n % 10;
    if l == 2 || l == 4 || l == 5 || l == 7 || l == 9 {
        return String::from("hon");
    } else if l == 0 || l == 1 || l == 6 || l == 8 {
        return String::from("pon");
    }
    String::from("bon")
}

Measured memory_bytes: 2132
import itertools
import math
n,d = map(int,input().split())
xlst = [list(map(int,input().split())) for _ in range(n)]
xxlst = list(itertools.combinations(xlst,2))
lst = [0]*len(xxlst)
index_num = 0
for i in xxlst:
    for j in range(d):
        lst[index_num] += (i[0][j] - i[1][j])**2
    index_num += 1
lst2 = list(map(math.sqrt,lst))
cnt = 0
for i in lst2:
    if i.is_integer():
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
i = input()

if i[-1]=="2" or i[-1]=="4" or i[-1]=="5" or i[-1]=="7" or i[-1]=="9":
  print("hon")
elif i[-1]=="0" or i[-1]=="1" or i[-1]=="6" or i[-1]=="8":
  print("pon")
else:
  print("bon")


Measured memory_bytes: 9044
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop pop_back()
#define sz size()
using namespace std;
typedef long long ll;
bool isPrime(ll n)
{
    if(n==1)
        return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
        return false;
    return true;
}
int lcm(ll a, ll b)
{
    ll temp = __gcd(a, b);

    return temp ? (a / temp * b) : 0;
}
unordered_map<ll,ll>mapp;
ll ma=-999,mi=10000000000;
///////////////////////////////////////////
ll n,m,i,j,in=-1,cnt,sum;
vector<ll>vi;
string s,t;
long double r;
ll a[200000],c,x,y;
int main(){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=-500;i<=500;i++){
            sum=0;
         for(j=0;j<n;j++){
            sum+=(i-a[j])*(i-a[j]);
         }
          mi=min(mi,sum);
    }
    cout<<mi;
}


Measured memory_bytes: 256