akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int H = in.i();
        int W = in.i();
        char[][] a = new char[H][];
        for (int i = 0; i < H; i++) {
            a[i] = in.s(W);
        }

        int[][] dp = new int[H + 1][W + 1];
        dp[0][1] = 1;
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if (a[i - 1][j - 1] == '.') {
                    dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
                }
            }
        }
        out.println(dp[H][W]);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 41392
#include<stdio.h>
#define N 100000
 
typedef struct pro{
  char name[10];
  int tim;
}P;
 
P Q[N+1];
int length,quantum;
int top,end;
 
void enqueue(P);
P dequeue(void);
void printqueue(void);
 
main(){

  int i;
  P p;
  int t_time=0;
  int count=0;
   
  scanf("%d %d",&length,&quantum);
   
  top = length/2;
  end = length/2;
   
  for(i=0; i<length; i++){
    scanf("%s %d",p.name,&p.tim);
    enqueue(p);
  }
 
  while(count != length){
     
    p = dequeue(); 
    if(p.tim > quantum){
      t_time += quantum;
      p.tim -= quantum;
      enqueue(p);
    }

    else{
      t_time += p.tim;
      printf("%s %d\n",p.name,t_time);    
      count++;
    }  
  }
  
  return 0;
}
 
void enqueue(P p){
   
  Q[end] = p;
  if(end == length){
    end = 0;
  }

  else
    end++;
}
 
P dequeue(){
  P x; 
 
  x = Q[top];
  if(top == length){
    top = 0;
  }

  else
    top++;
   
  return x;
}
 
void printqueue(void){
  int i;
   
  for(i=top; i!=end; i++){
    if(i==length){
      printf("%s %d ",Q[i].name,Q[i].tim);
      i=0;
      printf("\n");
    }

    printf("%s %d ",Q[i].name,Q[i].tim);
    printf("\n");
  } 
}

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

int main(){
    int S, h, m, s;
    cin >> S;
    h = S / 3600;
    m = (S % 3600) / 60;
    s = S - (h * 3600 + m * 60);
    
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>

int main(){
  long x,y,n[3],pqr[3][100005][3],h,i,j,k,app[3][100005],temp,prev,start[3],m,c[3]={0,0,0},t[3],pp;
  scanf("%ld",&c[0]);
  scanf("%ld",&c[1]);
  scanf("%ld",&n[0]);
  scanf("%ld",&n[1]);
  scanf("%ld",&n[2]);
  for(i=0;i<3;i++){
    for(j=0;j<n[i];j++){
      scanf("%ld",&pqr[i][j][0]);
      pqr[i][j][1]=-1;
      pqr[i][j][2]=j+1;
    }
    pqr[i][n[i]-1][2]=-1;
    start[i]=0;
  }
  for(h=0;h<3;h++){
    while(pqr[h][start[h]][2]!=-1){
      prev=-1;
      i=start[h];
      while(i!=-1){
        j=i;
        k=pqr[h][j][2];
        if(k==-1) break;
        i=pqr[h][k][2];
        pqr[h][j][2]=i;
        if(pqr[h][j][0]<pqr[h][k][0]){
          if(prev==-1){
            start[h]=k;
          }else{
            pqr[h][prev][2]=k;
          }
          temp=j;
          j=k;
          k=temp;
        }
        prev=j;
        while(k!=-1){
          if((j==-1)||(pqr[h][j][0]<pqr[h][k][0])){
            temp=pqr[h][k][1];
            pqr[h][k][1]=pqr[h][pp][1];
            pqr[h][pp][1]=k;
            pp=k;
            k=temp;
          }else{
            pp=j;
            j=pqr[h][pp][1];
          }
        }
      }
    }
    t[h]=0;
    for(i=0;i<n[h];i++){
      app[h][i]=pqr[h][start[h]][0];
      if(i<c[h]) t[h]+=app[h][i];
      start[h]=pqr[h][start[h]][1];
    }
  }
  m=t[0]+t[1];
  start[0]=c[0]-1;
  start[1]=c[1]-1;
  for(start[2]=0;start[2]<n[2];start[2]++){
    if(start[0]!=-1){
      if(start[1]!=-1){
        if(app[0][start[0]]<app[1][start[1]]){
          if(app[0][start[0]]>=app[2][start[2]]) break;
          m-=app[0][start[0]];
          start[0]--;
        }else{
          if(app[1][start[1]]>=app[2][start[2]]) break;
          m-=app[1][start[1]];
          start[1]--;
        }
      }else{
        if(app[0][start[0]]>=app[2][start[2]]) break;
        m-=app[0][start[0]];
        start[0]--;
      }
    }else{
      if(start[1]==-1) break;
      if(app[1][start[1]]>=app[2][start[2]]) break;
      m-=app[1][start[1]];
      start[1]--;
    }
    m+=app[2][start[2]];
  }
  printf("%ld",m);
  return(0);
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll n,k;cin >> n >>k;
    vpl v(n);
    rep(i,n)cin >> v[i].se >> v[i].fi;
    sort(all(v));rev(all(v));
    ll sum=0;
    set<ll> s;
    priority_queue<ll,vl,greater<ll>> que;
    rep(i,k){
        sum+=v[i].fi;
        if(s.count(v[i].se))que.push(v[i].fi);
        s.ins(v[i].se);
    }
    ll ans=sum+s.size()*s.size();
    //cout << ans <<endl;
    repl(i,k,n){
        if(s.count(v[i].se))continue;
        if(que.empty())continue;
        sum-=que.top();
        que.pop();
        sum+=v[i].fi;
        s.ins(v[i].se);
        ll t=s.size();t*=t;
        chmax(ans,sum+t);
    }
    cout << ans <<endl;
}

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

int main() {
  long long int N, K;
  cin >> N >> K;
  vector<long long int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    A.at(i)--;
  }
  
  
  set<long long int> visited;
  visited.insert(0);
  vector<long long int> cycle;
  cycle.push_back(0);
  long long int now = 0;
  long long int p;
  while (true) {
    int next = A.at(now);
    if (visited.count(next)) {
      p = next;
      break;
    }
    else {
      visited.insert(next);
      cycle.push_back(next);
    }
    now = next;
  }
  
  long long int V = cycle.size();
  for (long long int i = 0; i < V; i++) {
    if (p == cycle.at(i)) {
      p = i;
      break;
    }
  }
  if (K < p) cout << cycle.at(K) + 1 << endl;
  else cout << cycle.at(p + (K - p) % (V - p)) + 1 << endl;
}

Measured memory_bytes: 15332
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;

int main() {
    int N, C;
    cin >> N >> C;
    vector<vi> D(C, vi(C));
    rep(i, C) {
        rep(j, C) {
            cin >> D[i][j];
        }
    }
    vector<vi> A(N, vi(N));
    rep(i, N) {
        rep(j, N) {
            cin >> A[i][j];
            A[i][j]--;
        }
    }

    vector<vi> m(3, vi(C));
    rep(i, N) {
        rep(j, N) {
            m[(i + j) % 3][A[i][j]]++;
        }
    }

    int diff = __INT32_MAX__;
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            if (i == j) continue;
            for (int k = 0; k < C; k++) {
                if (i == k || j == k) continue;

                // 色aを色iに塗り替える
                int acnt = 0;
                for (int a = 0; a < C; a++) {
                    // 既に塗られている場合
                    if (i == a) continue;
                    // 塗り替える個数 * 塗り替えるコスト
                    acnt += m[0][a] * D[a][i];
                }

                // 色jを色bに塗り替える
                int bcnt = 0;
                for (int b = 0; b < C; b++) {
                    // 既に塗られている場合
                    if (j == b) continue;
                    // 塗り替える個数 * 塗り替えるコスト
                    bcnt += m[1][b] * D[b][j];
                }

                // 色kを色cに塗り替える
                int ccnt = 0;
                for (int c = 0; c < C; c++) {
                    // 既に塗られている場合
                    if (k == c) continue;
                    // 塗り替える個数 * 塗り替えるコスト
                    ccnt += m[2][c] * D[c][k];
                }
// cout << "i: " << i << ", j:  " << j << ", k: " << k << endl;
// cout << "acnt: " << acnt << ", bcnt: " << bcnt << ", ccnt: " << ccnt << endl;
                diff = min(diff, acnt + bcnt + ccnt);
            }
        }
    }
    cout << diff << endl;
}

Measured memory_bytes: 4504
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()

typedef long long int ll;

ll general,total;
//ll num[ten5];
//ll num2[ten5];
//char cmap[10][10];
//priority_queue<ll> pqll;   //decrease
//priority_queue<double> pqd;
//stack<int> stk;
//vector<pair<ll,ll>> vpll;
//vector<pair<double,double>> vpdd;
//vector<ll> vll[ten52];
//vector<double> vd;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
set<char> sch;
//map<ll,ll> mp;

ll numR[4000],numG[4000],numB[4000];

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/


int main()
{
    double ans=0.0,half,d,d1,d2;
    //float f,g,h;
    string s,s1;
    //char now,pre,c1,c2;
    long long int sum,sum2,n1,n2,n3;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    sum=sum2=n1=n2=n3=0;
    a=a1=a2=a3=a4=a5=a6=0;
    cin>>n>>m;
    if(m>=n) cout<<"unsafe";
    else cout<<"safe";
    return 0;
}





Measured memory_bytes: 3632
integer N,K
integer,allocatable,dimension(:)::A
integer Asum,ans
read*,N,K
allocate(A(N))
read*,A
Asum=sum(A)
ans=1
do j=1,Asum
  if(j*j>Asum)exit
  if(mod(Asum,j)==0)then
    if(check(j))ans=max(ans,j)
    if(check(Asum/j))ans=max(ans,Asum/j)
  endif
end do
print"(i0)",ans
contains
function check(M)
  integer M
  logical check
  integer,allocatable,dimension(:)::D
  integer dsum
  allocate(D(N))
  do i=1,N
    D(i)=mod(A(i),M)
  end do
  call heapsort(N,D)
  dsum=sum(D)
  do i=1,sum(D)/M
    dsum=dsum-D(N-i+1)
  end do
  check=(DSum<=K)
  deallocate(D)
end function
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  integer::i,k,j,l
  integer:: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end

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

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  1e+5+7;

vll adj[MAXN];ll visited[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,m,x,y;
stack<ll>Stack;
vll v1;
ll lis[100005];
//<<-----Implement Functions Here---->>//
void topologicalSortUtil(ll v) 
{ 
  	visited[v] = 1;
    for (auto it:adj[v])if(!visited[it])topologicalSortUtil(it); 
    Stack.push(v); 
} 

//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n>>m;
		for(ll i=0;i<m;i++){cin>>x>>y;adj[x].pb(y);}
		for(ll i=1;i<=n;i++)lis[i] = 1;
		for (int i = 1; i <=n; i++) 
      	{
      		if(!visited[i])topologicalSortUtil(i); 
      	}
      	while(!Stack.empty()){v1.pb(Stack.top());Stack.pop();} 
      	//for(auto it:v1)cout<<it<<" ";cout<<endl;
      	for(auto it:v1)
      	{
      		for(auto it1:adj[it])
      		{
      			lis[it1] =max(lis[it1],lis[it]+1);
      		}
      	}
      	ll max1 = -1;
      	for(ll i=1;i<=n;i++)max1 = max(lis[i],max1);
      	cout<<max1-1;
     

		
}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

   
}

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

void solve(pair<int, int> &a, pair<int, int> &b, pair<int, int> &c);

int main() {
  vector<pair<int, int>> hw(6);
  int i;
  for (i = 0; i < 6; i++) {
    cin >> hw[i].first >> hw[i].second;
    if (hw[i].first > hw[i].second) {
      swap(hw[i].first, hw[i].second);
    }
  }
  sort(hw.begin(), hw.end());
  bool result = true;
  vector<pair<int, int>> p(3);
  for (i = 0; i < 3; i ++) {
    if (!(hw[i * 2] == hw[i * 2 + 1])) {
      result = false;
      goto OUTPUT;
    } else {
      p[i] = hw[i * 2];
    }
  }

  for (i = 1; i < 3; i++) {
    if (p[i].first == p[i].second) {
      swap(p[0], p[i]);
    }
  }
  
  solve(p[0], p[1], p[2]);
  solve(p[1], p[2], p[0]);
  solve(p[2], p[0], p[1]);

  if (p[0] == p[1] && p[1] == p[2] && p[0].first == 0 && p[0].second == 0) {
    result = true;
  } else {
    result = false;
  }

  OUTPUT:
  cout << (result ? "yes" : "no") << endl;

  return 0;
}

void solve(pair<int, int> &a, pair<int, int> &b, pair<int, int> &c) {
  if (a.first == b.first) {
    a.first = 0;
    b.first = 0;
  } else if (a.first == b.second) {
    a.first = 0;
    b.second = 0;
  } else if (a.first == c.first) {
    a.first = 0;
    c.first = 0;
  } else if (a.first == c.second) {
    a.first = 0;
    c.second = 0;
  }
  if (a.second == b.first) {
    a.second = 0;
    b.first = 0;
  } else if (a.second == b.second) {
    a.second = 0;
    b.second = 0;
  } else if (a.second == c.first) {
    a.second = 0;
    c.first = 0;
  } else if (a.second == c.second) {
    a.second = 0;
    c.second = 0;
  }
  return;
}



Measured memory_bytes: 3100
h, n = map(int, input().split())
AB = []
for i in range(n):
    a, b = map(int, input().split())
    AB.append((a, b))

INF = 10**18
dp = [INF]*(h+1)
dp[h] = 0
for i in reversed(range(h+1)):
    for j in range(n):
        a,b = AB[j]
        if i-a >= 0:
            dp[i-a] = min(dp[i-a], dp[i]+b)
        else:
            dp[0] = min(dp[0], dp[i]+b)
print(dp[0])


Measured memory_bytes: 73812
#include<stdio.h>
#include<math.h>
int main(void){
  double x1,y1,x2,y2,x3,y3;
  double px,py,r;
  double a,b,c,d,e,f;
  int n,k;
  scanf("%d",&n);
  for(k=1;k<=n;k++){
    scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
    a=2*(x1-x2),b=2*(y1-y2),c=(x1*x1+y1*y1)-(x2*x2+y2*y2);
    d=2*(x2-x3),e=2*(y2-y3),f=(x2*x2+y2*y2)-(x3*x3+y3*y3);
    px = (e*c-b*f)/(e*a-b*d);
    py = (f*a-c*d)/(e*a-b*d);
    r = sqrt(pow((x1-px),2)+pow((y1-py),2));
    if(px==-0) px=0;
    if(py==-0) py=0;
    if(r==-0) r=0;
    printf("%.3lf %.3lf %.3lf\n",px,py,r);
  }
  return 0;
}

Measured memory_bytes: 664
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=2005;
struct Bitset{
	uint a[64];
	Bitset(){
		memset(a,0,sizeof(a));
	}
	Bitset operator &(const Bitset &b)const{
		Bitset ans;
		for (int i=0;i<64;i+=4){
			ans.a[i+0]=a[i+0]&b.a[i+0];
			ans.a[i+1]=a[i+1]&b.a[i+1];
			ans.a[i+2]=a[i+2]&b.a[i+2];
			ans.a[i+3]=a[i+3]&b.a[i+3];
		}
		return ans;
	}
	Bitset operator ^(const Bitset &b)const{
		Bitset ans;
		for (int i=0;i<64;i+=4){
			ans.a[i+0]=a[i+0]^b.a[i+0];
			ans.a[i+1]=a[i+1]^b.a[i+1];
			ans.a[i+2]=a[i+2]^b.a[i+2];
			ans.a[i+3]=a[i+3]^b.a[i+3];
		}
		return ans;
	}
	void operator |=(const Bitset &b){
		for (int i=0;i<64;i+=4){
			a[i+0]|=b.a[i+0];
			a[i+1]|=b.a[i+1];
			a[i+2]|=b.a[i+2];
			a[i+3]|=b.a[i+3];
		}
	}
	bool check(int x){
		return (a[x>>5]>>(x&31))&1;
	}
	void set(int x){
		a[x>>5]|=1u<<(x&31);
	}
};
Bitset par[N],g[N],all,sta;
Bitset son[N],nson[N];
vector<int> e[N],vec[N];
int dfn[N],ed[N],n,m,t,T;
int top[N][N],L[N][N];
pii q[N*N];
void dfs(int x,int fa){
	vec[x].PB(x);
	dfn[x]=++T;
	For(i,0,e[x].size()-1){
		int to=e[x][i];
		if (to==fa) continue;
		dfs(to,x);
		For(j,0,vec[to].size()-1)
			top[x][vec[to][j]]=to;
		For(j,0,vec[to].size()-1)
			For(k,0,vec[x].size()-1)
				L[vec[to][j]][vec[x][k]]=x;
		For(j,0,vec[to].size()-1)
			vec[x].PB(vec[to][j]);
	}
	ed[x]=T;
}
bool isfa(int x,int y){
	return dfn[x]<=dfn[y]&&ed[y]<=ed[x];
}
void adde(int x,int y){
	//printf("adde %d %d\n",x,y);
	if (g[x].check(y)) return;
	g[x].set(y); g[y].set(x);
	q[++t]=pii(x,y);
}
void work(int id,const Bitset &a){
	//printf("work %d %d\n",id,a.a[0]);
	For(i,0,63) if (a.a[i])
		For(j,0,31) if (a.a[i]&(1u<<j))
			adde(id,(i<<5)|j);
}
int main(){
	scanf("%d%d",&n,&m);
	For(i,0,n-1) all.set(i);
	For(i,1,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		e[--x].PB(--y);
		e[y].PB(x);
	}
	dfs(0,-1);
	For(i,0,n-1) For(j,0,vec[i].size()-1){
		son[i].set(vec[i][j]);
		par[vec[i][j]].set(i);
	}
	For(i,0,n-1)
		nson[i]=son[i]^all;
	For(i,0,n-1) g[i].set(i);
	For(i,1,m){
		int x,y;
		scanf("%d%d",&x,&y);
		q[++t]=pii(--x,--y);
		g[x].set(y); g[y].set(x);
	}
	For(i,1,t){
		int x=q[i].fi,y=q[i].se,LCA=L[x][y]|L[y][x];
		sta=par[x]^par[y]; sta.set(LCA);
		//printf("%d %d %d\n",x,y,sta.a[0]);
		if (isfa(x,y)) sta|=nson[top[x][y]];
		else sta|=son[x];
		if (isfa(y,x)) sta|=nson[top[y][x]];
		else sta|=son[y];
		//printf("%d %d %d %d %d\n",x,y,sta.a[0],g[x].a[0],g[y].a[0]);
		work(x,sta&g[y]&(all^g[x]));
		work(y,sta&g[x]&(all^g[y]));
	}
	printf("%d\n",t);
}


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


int main(){
  int n;
  cin >> n;
  map<string,int> mp;
  for(int i=0;i<n;++i){
    string s;
    cin >> s;
    mp[s]++;
  }
  int ans=mp.size();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 19224
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  ll cnt_four = 0, cnt_oeven = 0, cnt_odd = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] % 4 == 0) {
      cnt_four++;
    } else if (a[i] % 2 == 0) {
      cnt_oeven++;
    } else {
      cnt_odd++;
    }
  }
  if (cnt_odd <= cnt_four || (N % 2 == 1 && (cnt_odd - cnt_four <= 1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 4036
N,M = map(int,input().split()) #Nスイッチ、M電球
K = []; S = []
for i in range(M):
  k, *s = map(int,input().split())
  for j in range(len(s)): #スイッチを0index
    s[j] -= 1 
  K.append(k)
  S.append(s)
#print(S)
#print(K)
P = list(map(int,input().split()))
ans = 0
for i in range(2**N):
  Switch= [0 for _ in range(N)]
  for j in range(N): #j個目が押されているか？
    if(i>>j)&1==1:
      Switch[j] = 1
  num = 0
  for k in range(M): #k個目の電球がついているか？
    temp = 0
    for x in S[k]:
      if Switch[x] == 1:
        temp += 1
    if temp%2 == P[k]:
      num += pow(2,k)
  #print(num)
  if num == pow(2,M)-1:
    ans += 1
print(ans)
    
               

Measured memory_bytes: 9184
using System;

namespace aoj5a
{
    class Program
    {
        static int Main(string[] args)
        {
            for (;;)
            {
                string[]HandW = (Console.ReadLine()).Split(' ');
                int H = int.Parse(HandW[0]);
                int W = int.Parse(HandW[1]);

                if(H+W == 0)
                {
                    return 0;
                }

                for (int i = 1; i <= H; i++)
                {
                    for (int j= 1; j <= W; j++)
                    {
                        bool frame = false;
                        if (i==1||i==H||j==1||j==W)
                        {
                            frame = true;
                        }
                        Console.Write(frame ? '#' : '.');
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }


            
        }
    }
}

Measured memory_bytes: 8848
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int k,a,b;
	cin>>k>>a>>b;
	if(a%k==0)
      cout<<"OK";
  	else if((a+(k-(a%k)))<=b)
      cout<<"OK";
  else
    cout<<"NG";
 
 
 return 0;
 }

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  string s;
  cin >> n >> s;

  int sharp = 0, ans = 0;
  rep(i, 0, n) {
    if (s[i] == '#')
      sharp++;
    else {
      if (sharp > 0) {
        sharp--;
        ans++;
      }
    }
  }

  cout << ans << endl;
}


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

int n, s[11];

inline void dfs(int x, int num)
{
	if(x > n)
	{
		for(int i = 1; i <= n; i++) putchar(s[i] + 'a' - 1);
		puts("");
		return;
	}
	for(int i = 1; i <= num; i++)
		s[x] = i, dfs(x + 1, num);
	s[x] = num + 1;
	dfs(x + 1, num + 1);
}

int main()
{
	scanf("%d", &n);
	s[1] = 1;
	dfs(2, 1);
	return 0;
}


Measured memory_bytes: 1536
import java.util.*;

public class Main {
    private static int[] numbers;
    private static Stack<Integer> stackB;
    private static Stack<Integer> stackC;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        sc.nextLine(); // remove empty line
        for (int i = 0; i < N; i++) {
            numbers = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            stackB = new Stack<>();
            stackC = new Stack<>();

            System.out.println(dfs(0) ? "YES" : "NO");
        }
    }

    private static boolean dfs(int ind) {
        if (ind == 10) return true; // last element;

        int topB, topC;
        if (stackB.empty()) {
            topB = 0;
        } else {
            topB = stackB.peek();
        }
        if (stackC.empty()) {
            topC = 0;
        } else {
            topC = stackC.peek();
        }

        int num = numbers[ind];
        if (topB < num && topC < num) {
            if (topB > topC) {
                stackB.push(num);
                return dfs(ind+1);
            } else {
                stackC.push(num);
                return dfs(ind+1);
            }
        } else if (topB < num) {
            stackB.push(num);
            return dfs(ind+1);
        } else if (topC < num) {
            stackC.push(num);
            return dfs(ind+1);
        }

        return false;
    }
}

Measured memory_bytes: 31940
#include <bits/stdc++.h>
using namespace std;
int main() {
    int K;
    cin >> K;
    string S;
    cin >> S;

    if (S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
}

Measured memory_bytes: 3632
//#pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(int i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(int i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(int i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    #define mp make_pair
    #define pb push_back
    #define M_PI           3.14159265358979323846  /* pi */
    typedef long double ld;
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef vector<ll> vi;
    const int maxN = 70224;

    void solve(){
      ll a,b,k;
      cin>>a>>b>>k;
      ll cnt=0;
      repD(i,min(a,b),1){
        if(a%i==0 && b%i==0) {
            //cout<<i<<endl;
            cnt++;
        }
        if(cnt == k){
          cout<<i<<endl;
          return;
        }
      }
    }
    
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      solve();
      return 0;
    }   

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
#define f first
#define s second
using namespace std;
const int INF=(int)0x3f3f3f3f;
const int MOD=(int)1e9+7;
const double eps=1e-9;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<long long> v(n),ans(n);
    for(int i=0;i<n;i++)
        cin>>v[i],ans[0]+=(i%2?-1:1)*v[i];
    for(int i=1;i<n;i++)
        ans[i]=2*v[i-1]-ans[i-1];
    prArr(ans,n);
    return 0;
}


Measured memory_bytes: 4668
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<cstring>
#include<algorithm>
#define ll long long
#define Max(x,y) ((x) > (y) ? (x) : (y))
#define Min(x,y) ((x) < (y) ? (x) : (y))
#define mod 1000000007
#define N 100010
using namespace std;
inline int read(){
	int x = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
	return x*f;
}

int n;
int a2,a1,a4;

int main(){
	n = read();
	for(int i = 1;i <= n;i++){
		int x = read();
		if(x%4 == 0){
			a4++;
			continue;
		}
		if(x%2 == 0){
			a2++;
			continue;
		}
		else a1++;
	}
	if(a2 == 0){
		if(a4+1 >= a1) puts("Yes");
		else puts("No");
		return 0;
	}
	if(a4 >= a1) puts("Yes");
	else puts("No");
	return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;



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

	int h , w;
	int n;
	cin >> h >> w >> n;
	
	vi a(n);
	rep(i , n){
		cin >> a[i];
	}
	
	vector<vi> grid(h , vi(w , 0));
	
	int x = 0 , y = 0;
	int go = 0;
	rep(i , n){
		int e = a[i];
		while(e--){
			grid[x][y] = i + 1;
			if(go == 0)++y;
			else --y;
			if(y >= w || y < 0){
				++x;
				if(go == 0){
					--y;
				}else{
					++y;
				}
				go ^= 1;
			}
		}
	}
	
	rep(i , h){
		rep(j , w){
			cout << grid[i][j] << " ";
		}
		cout << nl;
	}

	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define int long long
using namespace std;
int n,i,j,t=1,a[100005];
int gcd(int a,int b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
signed main()
{
	scanf("%lld",&n);
	for(i=1;i<=n;++i)
		scanf("%lld",&a[i]);
	while(1)
	{
		for(i=1,j=0;i<=n;++i)
		{
			if(a[i]==1)
				break;
			if(a[i]%2==0)
				++j;
		}
		if(i<=n)
		{
			for(i=1,j=0;i<=n;++i)
				j=(j+a[i]-1)%2;
			if(j)
				printf(t?"First":"Second");
			else
				printf(t?"Second":"First");
			return 0;
		}
		if(j==0)
		{
			printf(t?"Second":"First");
			return 0;
		}
		if(j%2==1)
		{
			printf(t?"First":"Second");
			return 0;
		}
		if(n-j>=2)
		{
			printf(t?"Second":"First");
			return 0;
		}
		for(i=1;i<=n;++i)
			if(a[i]&1)
			{
				--a[i];
				break;
			}
		j=a[1];
		for(i=2;i<=n;++i)
			j=gcd(j,a[i]);
		for(i=1;i<=n;++i)
			a[i]/=j;
		t=1-t;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    int res['z'-'a'+1] = {};

    for(int i = 'a'; i <= 'z'; i++)
        res[i-'a'] = 100;


    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;

        int tmp['z'-'a'+1] = {};

        for (int j = 0; j < s.size(); j++) {
            tmp[s[j]-'a']++;
        }

        for (int j = 'a'; j <= 'z'; j++) {
            res[j-'a'] = min(res[j-'a'],tmp[j-'a']);
        }

    }

    string result = "";

    for (int i = 'a'; i <= 'z'; i++) {
        for(int j = 0; j < res[i-'a']; j++)
            result += (char)i;

    }

    cout << result << endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    final int N = sc.nextInt(), M = sc.nextInt(), Q = sc.nextInt();
    int[][] abcd = new int[Q][4];
    for(int i=0;i<Q;i++){
      for(int j=0;j<4;j++){
        abcd[i][j] = sc.nextInt();
      }
    }
    Queue<Integer[]> queue = new ArrayDeque<>();
    for(int i=1;i<=M;i++){
      Integer[] arr = {i};
      queue.add(arr);
    }
    while(queue.peek().length < N){
      Integer[] arr = queue.poll();
      int tail = arr[arr.length-1];
      for(int i=tail;i<=M;i++){
      	Integer[] arr_temp = new Integer[arr.length+1];
     	for(int j=0;j<arr.length;j++){
          arr_temp[j] = arr[j];
      	}
        arr_temp[arr_temp.length-1] = i;
        queue.add(arr_temp);
      }
    }
    
    int size = queue.size();
    int score = 0;
    for(int i=0;i<size;i++){
      Integer[] arr = queue.poll();
      int sc_temp = 0;
      for(int j=0;j<Q;j++){
        if(arr[abcd[j][1]-1] - arr[abcd[j][0]-1] == abcd[j][2]){
          sc_temp += abcd[j][3];
        }
      }
      score = Math.max(score, sc_temp);
    }
    System.out.println(score);
  }
  
}

Measured memory_bytes: 39004
using System;
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var max = ToInt32(ReadLine());
        for(var i = max; i > 0; i--)
        {
            if (FigureBreak(i)) { WriteLine(i); break; }
        }
    }

    private static bool FigureBreak(int num)
    {
        var result = false;
        for(var i = 2; i< num; i++)
        {
            if (num % i == 0)
            {
                if (num == Math.Pow(i, 2) || num == Math.Pow(i, 3)) { result = true; break; }
                var num1 = num;
                while (num1 % i == 0)
                {
                    num1 /= i;
                }
                if (num1 == 1) { result = true;break; }
            }
        }
        if (num == 1) result = true;
        return result;
    }
}



Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A,B;
  cin >> A >> B;
  int ans=0;
  for(int j=A; j<=B; j++){
    int i=j;
    int a=i%10;
    i /= 10;
    int b=i%10;
    i /= 10;
    int c=i%10;
    i /= 10;
    int d=i%10;
    i /= 10;
    int e=i%10;

    if(a==e && b==d) ans++;
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
weight = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1]*(N+1)
dp[0] = 0
for i in range(N+1):
    for a in A:
        if i + weight[a]<=N:
            dp[i+weight[a]] = max(dp[i+weight[a]],dp[i]*10+a)
print(dp[N])

Measured memory_bytes: 14692
#include <cstdio>
#include <cmath>

int main() {
    double r;
    scanf("%lf", &r);

    double area = M_PI * r * r;
    double circumference = M_PI * 2.0 * r;

    printf("%.5f %.5f\n", area, circumference);
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	double l; cin >> l;
	printf("%.15f\n", pow(l / 3.0, 3));
	return 0;
}

Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, t;
    cin >> n >> t;
    akari<int> dp(t + 1, -1e9);
    akari<pair<int, int>> ps(n);
    for (int i = 0; i < n; i++)
    {
        cin >> ps[i].first >> ps[i].second;
    }
    sort(ps.begin(), ps.end());
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        int a = ps[i].first, b = ps[i].second;
        for (int j = t - 1; j >= 0; j--)
        {
            dp[min(t, j + a)] = max({dp[min(t, j + a)], dp[j] + b, dp[min(t, j + a - 1)]});
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
import heapq
from collections import defaultdict
v_num = int(input())
edges = defaultdict(list)
for i in range(v_num):
    data = [int(n) for n in input().split(" ")[1:]]
    for j in range(i + 1, v_num):
        if data[j] != -1:
            edges[i].append([data[j], j])
            edges[j].append([data[j], i])
queue = []
heapq.heapify(queue)
for c in edges[0]:
    heapq.heappush(queue, c)
visited = {0}
answer = 0
while len(visited) < v_num:
    q = heapq.heappop(queue)
    weight, one = q[0], q[1]
    if one in visited:
        continue
    answer += weight
    for e in edges[one]:
        heapq.heappush(queue, e)
    visited |= {one}
print(answer)

Measured memory_bytes: 8724
#include <bits/stdc++.h>
#include <string>
using namespace std;
int N,M;

int main(){
    int b[100];
    cin >> N;
    for(int i=0;i<N-1;i++){
        cin >> b[i];
    }
    int a[100];
    for(int i=0;i<N;i++){
        if(i==0) a[0]=b[0];
        else if(i==N-1) a[i]=b[i-1];
        else {
            int tmp;
            tmp = min(b[i-1],b[i]);
            a[i]=min(tmp,b[i]);
        }
    }
    int ans=0;
    for(int i=0;i<N;i++){
        ans += a[i];
        // cout << a[i]<< endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::io::stdin;

fn main() {
    let (_, k) = {
        let vec: Vec<u64> = read_vec();
        (vec[0], vec[1])
    };
    let vec: Vec<u64> = read_vec();
    let count = vec.iter().filter(|&&i| i >= k).count();
    println!("{}", count);
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;



struct Q{
    int x;
    int y;
    Q(int a, int b){
        x=a, y=b;
    } 
};

int main(){
    int h, w;
    cin >> h >> w;
    char map[h][w];
    int dist[h][w];
    int b_num=0, w_num=0;
    int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
    REP(x, h)
        REP(y, w){
            char tmp;
            cin >> tmp;
            if(tmp=='#') b_num++;
            else w_num++;
            map[x][y]=tmp;
            dist[x][y]=-1;
        }

    queue<Q> que;
    que.push(Q(0,0));
    dist[0][0]=0;
    while(!que.empty()){
        Q c_node = que.front();
        que.pop();
        REP(i, 4){
            Q n_node = Q(c_node.x+dx[i], c_node.y+dy[i]);
            if(0<=n_node.x && n_node.x<h && 0<=n_node.y && n_node.y<w &&
               map[n_node.x][n_node.y]=='.' &&dist[n_node.x][n_node.y]==-1)
            {
                que.push(n_node);
                dist[n_node.x][n_node.y] = dist[c_node.x][c_node.y]+1;
            }
        }
    }
    if(dist[h-1][w-1] == -1) cout << -1 << endl;
    else cout << w_num - dist[h-1][w-1] -1<< endl;
    
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    unordered_set<string> mem;
    for(int i=0;i<=9;i++){
        for(int j=0;j<=9;j++){
            for(int k=0;k<=9;k++){
                string tmp = to_string(i) + to_string(j) + to_string(k);
                int idx = 0;
                for(int x=0;x<n && idx < 3;x++){
                    if(s[x] == tmp[idx]){
                        idx++;
                    }
                }

                if(idx==3){
                    mem.insert(tmp);
                }
            }
        }
    }
    cout<<(int)mem.size()<<"\n";
    return 0;

}




Measured memory_bytes: 512
#include <stdio.h>
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;

  for(i = 0; i < n1; i++){
    L[i] = A[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }

  L[n1] = R[n2] = SENTINEL;

  i = 0;
  j = 0;

  for(k = left; k < right; k++){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[], int n, int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}


int main(){
  int A[MAX], n, i;
  cnt = 0;

  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&A[i]);

  mergeSort(A,n,0,n);

  for(i = 0; i < n; i++){
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  
  printf("%d\n",cnt);

  return 0;
}



Measured memory_bytes: 5688
/* 
    Author - linpaws07 
*/
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define inf (int)1e9
#define f first
#define s second
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define scd(t) scanf("%d",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define memst(a, b) memset(a, (b), sizeof(a))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rp(i,n) for(int i=0;i<(n);i++)
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define fre(i,a,b) for(int i=(a);i<=(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
inline bool eq(double a, double b) { return fabs(a-b) < 1e-9; }
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
auto start = high_resolution_clock::now();
inline void measure();

double p[3002];
double dp[3002][3002];
int main(){
    FAST
    //Do awesome things here
    int n;
    cin >> n;
    double ans = 0;
    fre(i, 1, n)    cin >> p[i];
    dp[0][0] = 1;
    fre(i, 1, n)    dp[i][0] = p[i] * dp[i - 1][0];
    fre(i, 1, n)    dp[0][i] = (1 - p[i]) * dp[0][i - 1];
    ans += dp[n][0];
    fre(i, 1, n){
        fre(j, 1, n - i){
            dp[i][j] = p[i + j] * dp[i - 1][j] + (1 - p[i + j]) * dp[i][j - 1];
            if(i > j && i + j == n)
                ans = ans + dp[i][j];
        }   
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


inline void measure(){
    auto stop = high_resolution_clock::now(); 
    auto duration = duration_cast<milliseconds>(stop - start);
    cout << duration.count() << endl;
}

Measured memory_bytes: 70016
n = int(input())
inp = []
for i in range(n-1):
    inp.append(list(map(int, input().split())))

for i in range(n-1):
    total = 0
    for j in range(i, n-1):
        if total < inp[j][1]:
            total = inp[j][1]
        while total % inp[j][2] != 0:
            total += 1
        total += inp[j][0]
    print(total)
print(0)
            





Measured memory_bytes: 9004
W, H, N = gets.split.map(&:to_i)

sx = 0
ex = W
sy = 0
ey = H

N.times do
  x, y, a = gets.split.map(&:to_i)

  case a
  when 1
    sx = [sx, x].max
  when 2
    ex = [ex, x].min
  when 3
    sy = [sy, y].max
  when 4
    ey = [ey, y].min
  end
end

dy = ey - sy
dx = ex - sx

if dy > 0 && dx > 0
  puts dy * dx
else
  puts 0
end


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

int main(){
    ll N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    vector<ll> x;
    x.push_back(0);
    char now = s[0];
    rep(i, 1, N){
        if(s[i] != now){
            x.push_back(i);
            now = s[i];
        }
    }
    x.push_back(N);

    rep(i, 0, x.size()) cerr << x[i] << " ";
    cerr << endl;

    ll ans = 0;
    rep(i, 0, x.size()){
        ll j = x[i];
        if(s[j] == '0'){
            ll v = x[min((ll)x.size()-1, i+2*K)] - j;
            ans = max(ans, v);
        }else{
            ll v = x[min((ll)x.size()-1, i+2*K+1)] - j;
            ans = max(ans, v);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1528
N = int(input())
x = list(map(int, input().split()))

def solve(num,ans,N,ite):
    count = 0
    ans.append(num)
    if len(ans) == N:
        a = 1
        for i in range(N):
            a *= ans[i]
        if a%2 == 0:
            return 1
        else:
            return 0
    for n in (-1,0,1):
        count += solve(x[ite+1]+n,ans[:],N,ite+1)
    return count
print(solve(x[0]-1,[],N,0)+solve(x[0],[],N,0)+solve(x[0]+1,[],N,0))

Measured memory_bytes: 3064