akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        final long MOD = 1000000007;
        // write reader
        int N = reader.nextInt();
        int K = reader.nextInt();
        // f(i) = （K個のボールをN-K+1箇所のうちi箇所に割り振る方法）
        //      = (N-K+1)_C_i * (K-1)_C_(i-1)
        long[][] C = new long[2001][2001];
        for (int i=0; i<=N; i++) {
            for (int j=0; j<=i; j++) {
                if (j==0 || j==i) C[i][j] = 1;
                else C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
            }
        }

        for (int i=1; i<=K; i++) {
            long ans = (C[N-K+1][i] * C[K-1][i-1]) % MOD;
            System.out.println(ans);
        }
    }
    
    public static void solver() {
        // write logic
    }
    
    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



Measured memory_bytes: 81876
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <unordered_map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

ll ans;
int N, M;
ll A[100005], S[100005];
unordered_map<ll, ll> um;

int main(void) {
    scanf("%d %d", &N, &M);
    rep(i, 1, N+1) scanf("%lld", &A[i]);

    rep(i, 1, N+1) S[i] = S[i-1] + A[i];

    rep(i, 1, N+1) {
        ll x = S[i]%M;
        if ( x==0 ) ans++;
        if (um[x] >= 1) ans += um[x];
        um[x]++;
    }

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

	return 0;
}


Measured memory_bytes: 5260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	vector<string> a = {"Sunny", "Cloudy", "Rainy"};
	// int t;
	// cin>>t;
	string s;
	cin>>s;
	if(s=="Sunny")
	{
		cout<<"Cloudy"<<endl;
	}
	if(s=="Cloudy")
	{
		cout<<"Rainy"<<endl;
	}
	if(s=="Rainy")
	{
		cout<<"Sunny"<<endl;
	}


}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def no():
    print("No")
def yes():
    print("Yes")
    
n=int(input().rstrip())

for a in range(1,10):
    for b in range(1,10):
        #print(a,end=" ")
        #print(b)
        if(a*b==n):
            yes()
            sys.exit()
no()


Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.function.Function;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    Scanner sc = new Scanner(System.in);

    void solve() {
        int n, m, l;
        long[][] m1, m2, m3;
        n = sc.nextInt();
        m = sc.nextInt();
        l = sc.nextInt();
        m1 = new long[n][];
        for (int i = 0; i < n; ++i) {
            m1[i] = new long[m];
            for (int j = 0; j < m; ++j) {
                m1[i][j] = sc.nextInt();
            }
        }
        m2 = new long[m][];
        for (int i = 0; i < m; ++i) {
            m2[i] = new long[l];
            for (int j = 0; j < l; ++j) {
                m2[i][j] = sc.nextInt();
            }
        }
        m3 = new long[n][];
        for (int i = 0; i < n; ++i) {
            m3[i] = new long[l];
            for (int j = 0; j < l; ++j) {
                long temp = 0;
                for (int k = 0; k < m; ++k) {
                    temp += m1[i][k] * m2[k][j];
                }
                m3[i][j] = temp;
            }
        }

        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < l - 1; ++j) {
                System.out.print(m3[i][j] + " ");
            }
            System.out.println(m3[i][l - 1]);
        }

    }

}




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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25


int main() {
    double a,b;
    cin >> a >> b;
    for(double ans = 1; ans <= 1250; ans++){
        if(floor(ans * 0.08) == a && floor(ans * 0.1) == b){
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}




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

#define rep(i, n) for(int (i) = 0; i < (n); ++(i))

typedef long long ll;
const ll MOD = 1e9 + 7;
const int MAX_S = 1e5;

int main() {
  std::string S;
  std::cin >> S;

  static ll dp[MAX_S + 1][13] = {};
  dp[0][0] = 1;
  rep(i, S.length()) {
    int c;
    if(S[i] == '?') c = -1;
    else c = S[i] - '0';

    rep(j, 10) {
      if(c != -1 && c != j) continue;
      rep(ki, 13) {
        dp[i + 1][(10 * ki + j) % 13] += dp[i][ki];
      }
    }
    rep(ki, 13) dp[i + 1][ki] %= MOD;
  }

  std::cout << dp[S.length()][5] << '\n';
}

Measured memory_bytes: 10624
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
n,m = map(int,readline().split())
a = list(map(int,readline().split()))
import heapq
heapq.heapify(a)

b = []
for i in range(m):
  c = list(map(int,readline().split()))
  b.append(c)
  
from operator import itemgetter
b = tuple(sorted(b,key=itemgetter(0),reverse=True))
b = tuple(sorted(b,key=itemgetter(1),reverse=True))

cnt = 0
for i in b:
  cnt += i[0]
  chk = i[0]
  for j in range(chk):
    p = heapq.heappop(a)
    if p >= i[1]:
      cnt += 10**5
      heapq.heappush(a,p)
      break
    heapq.heappush(a,i[1])
  if cnt >= n:
    break
print(sum(a))

Measured memory_bytes: 33856
// ※※※ 解答不能 ※※※
// LHiC氏.
// https://atcoder.jp/contests/code-festival-2016-qualb/submissions/921136
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const int MAXN = 120000;
const int MX = 450000;
int go[MX][26];
int cc[MX];
int fl[MX];
int nowcc = 1;
int gg[26][26];
int gg2;
int aa2[MAXN];
int aa[MAXN][26][26];
int n, q;

int newn(){
    fl[nowcc] = -1;
    return nowcc++;
}

void add(const string &s, int i){
    int now = 0;
    rep(i, (int)s.size()){
        ++cc[now];
        if(go[now][s[i] - 'a']) now = go[now][s[i] - 'a'];
        else                    now = go[now][s[i] - 'a'] = newn();
    }
    ++cc[now];
    fl[now] = i;
}

void dfs1(int v){
    if(fl[v] != -1){
        memcpy(aa[fl[v]], gg, sizeof(gg));
        aa2[fl[v]] = gg2;
    }
    if(fl[v] != -1) ++gg2;
    rep(i, 26){
        if(go[v][i]){
            rep(j, 26) if(go[v][j] && j != i) gg[i][j] += cc[go[v][j]];
            dfs1(go[v][i]);
            rep(j, 26) if(go[v][j] && j != i) gg[i][j] -= cc[go[v][j]];
        }
    }
    if(fl[v] != -1) --gg2;
}

char buf[MX];
string s[MAXN];

int main(){
    scanf("%d", &n);
    fl[0] = -1;
    rep(i, n){
        scanf(" %s", buf);
        s[i] = buf;
        add(s[i], i);
    }
    dfs1(0);
    scanf("%d", &q);
    rep(i, q){
        int k;
        scanf("%d%s", &k, buf);
        --k;
        int ans = 1 + aa2[k];
        rep(j, 26) repx(l, j + 1, 26) ans += aa[k][buf[l] - 'a'][buf[j] - 'a'];
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 287744
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<bool> t(n,1);
  for(int i=0;i<k;i++){
    int d;
    cin>>d;
    for(int i=0;i<d;i++){
      int a;
      cin>>a;
      t.at(a-1)=0;
    }
  }
  int c=0;
  for(int i=0;i<n;i++)
    if(t.at(i))
      c++;
  cout<<c<<endl;
}

Measured memory_bytes: 3632
#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string s;
int main()
{
	cin>>s;
	if(s[0]==s[2])
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int gcd(int a,int b){
    if(a%b == 0) return b;
    else return gcd(b,a%b);
    return 0;
}

int main(){
    int K,tmp,i,j,l;
    long ans = 0;
    scanf("%d",&K);
    for(i = 1; i <= K; i++){
        for(j = 1; j <= K; j++){
            for(l = 1; l <= K; l++){
                tmp = gcd(i,j);
                tmp = gcd(tmp,l);
//                printf("%d %d %d gcd is %d\n",i,j,l,tmp);
                ans += tmp;
                tmp = 0;
            }
        }
    }
    printf("%ld\n",ans);
    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

int main(){
    long double q,h,s,d;
    cin >> q >> h >> s >> d;
    ll n;
    cin >> n;
    q *= 4;
    h *= 2;
    d /= 2;
    ll ans = 0;
    if(min({q,h,d,s}) == d){
        ans += n/2 *(2*d);
        n %= 2;
    }
    ans += min({q,h,s})*n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<x86intrin.h>
#include<math.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}


int main(){
    int A,X;

    scanf("%d %d%*c",&X,&A);

    printf("%d\n",(X<A)?(0):(10));

    
    return 0;
}

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

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll count=0;
  set<char> check;
  for(ll i=0;i<n;i++) {
    if(check.count(s[i])) {
      continue;
    }
    check.insert(s[i]);
    set<char> check2;
    for(ll j=i+1;j<n;j++) {
      if(check2.count(s[j])) {
        continue;
      }
      check2.insert(s[j]);
      set<char> check3;
      for(ll k=j+1;k<n;k++) {
        if(check3.count(s[k])) {
          continue;
        }
        check3.insert(s[k]);
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main(){
    int N;
    cin >> N;
    vector<ll> a(3*N);
    rep (i,3*N){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll ans=0;
    for (int i=0;i<N;i++){
        ans+=a[3*N-2-2*i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if(s.size() == 2){
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI (acos(-1))
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using Complex = std::complex<double>;
using namespace std;


int N;
VI A;


int solve(){
	VI B;
	for(int i = 1;N-i > 1;i+=2) B.pb(N-i), B.pb(N-i);
	if(N%2 == 0) B.pb(1), B.pb(1);
	else B.pb(0);
	sort(ALL(B));
	rep(i, 0, SIZE(B))
		if(B[i] != A[i]) return 0;
	int ans = 1;
	rep(i, 0, N/2) ans = MUL(ans, 2);
	return ans;
}


signed main(){
	cin >> N;
	rep(i, 0, N){
		int a;
		cin >> a;
		A.pb(a);
	}

	sort(ALL(A));

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i < b;i++)
#define rrep(i,a,b) for(int i=b ; i > a ; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define check1(a) cerr << a << endl
#define check2(a,b) cerr << a << "|" << b << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
/*----------------------------------------------*/
int main()
{
	ll x,y;
	cin >> x >> y;
	if(x == y){
		cout << "-1" ;
		return 0;}
	ll gc = __gcd(x,y);
	ll lc = (x*y)/gc;
	if(lc-x <= 0){
		cout << "-1";
		return 0;  }
	else{
		cout << x;}
		            

	
	
	

	return 0;
}

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

int numofbits(long bits)
{
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main()
{
  ll N; cin >> N;
  vector<vector<ll>> a(N, vector<ll>(N));
  for (int i=0; i<N; i++){
    for (int j=0; j<N; j++){
      cin >> a[i][j];
    }
  }

  vector<vector<ll>> dp(N+1, vector<ll>(1LL<<N, 0));
  dp[0][0] = 1;
  for (int i=0; i<N; i++) {
    for (ll bits=0; bits<1LL<<N; bits++) {
      if (numofbits(bits) != i) continue;
      for (int j=0; j<N; j++) {
        if (bits&(1LL<<j) || a[i][j]==0) continue;
        dp[i+1][bits|(1LL<<j)] = (dp[i+1][bits|(1LL<<j)]+dp[i][bits]) % mod;
      }
    }
  }
  cout << dp[N][(1<<N)-1] << endl;

  return 0;
}


Measured memory_bytes: 377216
N, K = list(map(int,input().split()))
a = list(map(int,input().split()))

for i in range(N):  a[i] -= K
dp = [[0 for _ in range(5500)] for _ in range(N + 5)]
dp[0][2500] = 1
for i in range(N):
    for j in range(5010):
        if j - a[i] >= 0 :  dp[i + 1][j] += dp[i][j - a[i]]
        dp[i + 1][j] += dp[i][j] 
        
ans = dp[N][2500] - 1
print(ans)

Measured memory_bytes: 74188
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD (ll) (1e9+7)
int main()
{
	ll a,b,c,d;
    cin>>a>>b>>c>>d;
    string ans = "";
    while(1)
    {
       c=c-b;
       if(c<=0)
       {
         ans = "Yes";
         break;
       }
       a = a-d;
      if(a<=0)
      {
        ans = "No";
        break;
      }
    }
   cout<<ans<<"\n";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define INF = 1001001001
#define pi = acos(-1)
using namespace std;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

ll func(ll n){
    if(n==1) return 1;
    return 2*func(n/2)+1;
}

int main(){
    ll h; cin>>h;
    ll ans = 0;

    ans = func(h);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-02-03 16:47:35
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

template<class T> T gcd(T x, T y) { return __gcd(x, y); }
template<class T> T lcm(T x, T y) { return x / gcd(x, y) * y; }

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

  int n; cin >> n;
  vector<int64> a(n); cin >> a;

  int64 ans = 1;
  for (int64 x : a) {
    ans = lcm(ans, x);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3220
// Ref : https://book.mynavi.jp/ec/products/detail/id=35408

#include <cstdio>
#define NMAX 25
#define NIL -1

struct Node {
	int parent, left, right;
};

struct Node T[NMAX];

int getSibling(int i) {
	int j = T[i].parent;
	if (j == NIL) return -1; // case of root node
	else if ((T[j].left != NIL) && (T[j].left != i)) return T[j].left;
	else if ((T[j].right != NIL) && (T[j].right != i)) return T[j].right;
	else return -1;
}

int getDegree(int i) {
	int deg = 0;
	if (T[i].left != NIL) deg++;
	if (T[i].right != NIL) deg++;
	return deg;
}

int getDepth(int i) {
	int depth = 0;
	while (T[i].parent != NIL) {
		i = T[i].parent;
		depth++;
	}
	return depth;
}

int getHeight(int i) {
	int h1 = 0, h2 = 0;
	if (T[i].left != NIL) h1 = getHeight(T[i].left) + 1;
	if (T[i].right != NIL) h2 = getHeight(T[i].right) + 1;
	if (h1 > h2) return h1;
	else return h2;
}

void print(int n) {
	for (int i = 0; i < n; i++) {
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", \
			i, T[i].parent, getSibling(i), getDegree(i), getDepth(i), getHeight(i));
		// judge a kind of node;
		if (T[i].parent == NIL) printf("root");
		else if ((T[i].left != NIL) || (T[i].right != NIL)) printf("internal node");
		else printf("leaf");
		printf("\n");
	}
}

int main() {
	int n, idx, left, right;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) T[i].parent = NIL;
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &idx, &left, &right);
		T[idx].left = left;
		T[idx].right = right;
		T[left].parent = T[right].parent = idx;
	}
	print(n);

	return 0;
}


Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int f=1,n=s.length();
  int i;
  for(i=0;i<n;i++){
    if(s[i]=='7'){
      f=1;
      break;
    }
   else f=0;}
  if(f)	cout << "Yes\n";
  else
    	cout << "No\n";
  return 0;}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <stack>
#include <set>

using namespace std;

int make_ballstack(vector<int>& balls) {
    int n=(int)balls.size();
    stack<pair<int,int> > stk_ball;
    int length;
    int ans=0;

    for(int i=0; i<n; ++i) {
        if(stk_ball.empty()) {
            balls[i];
            length=1;
            ans=1;
            stk_ball.push(make_pair(balls[i],length));
        } else if(stk_ball.top().first==balls[i]) {
            length=stk_ball.top().second; stk_ball.pop();
            ++length;
            ++ans;
            stk_ball.push(make_pair(balls[i],length));
        } else {
            length=stk_ball.top().second;
            if(length>=4) {
                ans-=length;
                stk_ball.pop();
                if(stk_ball.empty()) {
                    stk_ball.push(make_pair(balls[i],1));
                } else if(stk_ball.top().first!=balls[i]) {
                    stk_ball.push(make_pair(balls[i],1));
                } else {
                    length=stk_ball.top().second;
                    stk_ball.pop();
                    stk_ball.push(make_pair(balls[i],length+1));
                }
            } else {
                stk_ball.push(make_pair(balls[i],1));
            }
            ++ans;
        }
    }
    if(stk_ball.top().second >= 4) {
        ans-=stk_ball.top().second;
        stk_ball.pop();
    }
    return ans;
}



int main() {
    int N;

    cin >> N;

    while(N!=0) {
        vector<int> balls;
        set<pair<int,int> > mark;
        int cont=1;
        int temp;
        int ans=N;

        for(int i=0; i<N; ++i) {
            cin >> temp;
            balls.push_back(temp);
            if(i>=1 && temp==balls[i-1]) ++cont;
            else {
                if(cont==3) {
                    mark.insert(make_pair(i,balls[i-1]));
                    if(i>=4) {
                        mark.insert(make_pair(i-4,balls[i-1]));
                    }
                }
                cont=1;
            };

        }

        for(auto x:mark) {
            int tempc=balls[x.first];
            balls[x.first]=x.second;
            ans=min(ans,make_ballstack(balls));
            balls[x.first]=tempc;
        }

        cout << ans << endl;

        cin >> N;
    }

    return 0;
}

Measured memory_bytes: 3192
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int y=0;
		int t=s.length()-1;
		int ans=0;
		while(t>y){
			if(s.charAt(y)==s.charAt(t)){
				t--;
				y++;
			}else if(s.charAt(y)=='x' || s.charAt(t)=='x'){
				ans++;
				if(s.charAt(y)=='x'){
					y++;
				}else{
					t--;
				}
			}else{
				System.out.println(-1);
				return;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 26772
#include "bits/stdc++.h"

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

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

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int sum = 0;
	vector<int> t(n);
	REP(i, n) {
		cin >> t[i];
		sum += t[i];
	}
	int m;
	cin >> m;
	vector<pair<int, int> > d;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		cout << sum - t[a-1] + b << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

main(void)
{
  int n;
  string str,order;
  unordered_map<string, int> mp;

  cin >> n;

  for(int i = 0;i < n;i++){
    cin >> order >> str;
    if(order[0] == 'i'){
      mp[str] = i;
    }
    else{
      auto itr = mp.find(str);
      if(itr != mp.end()){
	cout << "yes" << endl;
      }
      else{
	cout << "no" << endl;
      }
    }
  }
  
  return 0;
}



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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;

  ll ans;
  for(ll i = 1; i*i <= n; i++){
    ans = i*i;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import sys

n, W = map(int, sys.stdin.readline().split())
wv = map(int, sys.stdin.read().split())

wv = sorted(zip(*[wv] * 2))
min_w = wv[0][0]
W2 = 4 * n

def main():
    dp = [[[0] * (W2 + 1) for _ in range(n+1)] for _ in range(n+1)]
    
    for i in range(n):
        w, v = wv[i]
        w -= min_w - 1
        for j in range(1, i+2):
            for k in range(W2 + 1):
                if k + (min_w - 1) * j > W:
                    break
                dp[i+1][j][k] = dp[i][j][k]
                if k >= w:
                    dp[i+1][j][k] = max(dp[i][j][k], dp[i][j-1][k-w] + v)

    res = 0
    for j in dp[n]:
        res = max(res, max(j))

    return res

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

Measured memory_bytes: 99696
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

#ifdef DEBUG
int __cnt = 0;
#define msg(x) cout << ++__cnt << '\t' << __FUNCTION__ << "(" << __LINE__ << "): " << x << endl
#else
#define msg(x)
#endif

typedef long long ll;
typedef unsigned long long ull;

template<typename T>
T _scan() {
  T ch; bool seg = false;
  while (!isdigit(ch = getchar())) {
    seg |= (ch == '-');
  }
  T x = ch - '0';
  while (isdigit(ch = getchar())) {
    x = x * 10 + ch - '0';
  }
  if (seg) {
    x = -x;
  }

  return x;
}

auto const scan = &_scan<int>;
auto const scan_ll = &_scan<ll>;

template<typename T>
T maximize(T& a, const T b) {
  if (b > a) {
    a = b;
  }
  return a;
}

template<typename T>
T minimize(T& a, const T b) {
  if (b < a) {
    a = b;
  }
  return a;
}



int main() {
  string s;
  cin >> s;
  int ans = 0;
  string val = "CODEFESTIVAL2016";
  for (int i = 0; i < val.length(); ++i) {
    if (s[i] != val[i]) {
      ++ ans;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> vec(N,0);
    for(auto &v:vec){
        cin >> v;
    }
    sort(vec.begin(),vec.end());
    int ans=0;
    for(int i=0; i<K; i++){
        ans+=vec[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3528
n = int(input())
a = [0] + list(map(int, input().split())) + [0]

cost=0
for i in range(1, n+2):
    cost+=abs(a[i]-a[i-1])

for i in range(1, n+1):
    if a[i-1]<=a[i]<=a[i+1]:
        print(cost)
    elif a[i-1]>=a[i]>=a[i+1]:
        print(cost)
    else:
        print(cost-2*min(abs(a[i]-a[i-1]), abs(a[i]-a[i+1])))

Measured memory_bytes: 14044
N, M, X, Y = map(int, input().split())
x = [int(_) for _ in input().split()]
y = [int(_) for _ in input().split()]
flag = False

x = sorted(x)
y = sorted(y)

if max(x) < min(y) and max(x) < Y and X < min(y):
    flag = True

print("No War" if flag else "War")

Measured memory_bytes: 3064
#include <vector>
#include <climits>
#include <cstdio>

void update(const int &index, std::vector<int> &vec){
	if (index % 2 == 0){
		if (index != 0){
			if (vec.at(index - 1) < vec.at(index)){
				if (vec.at((index - 1) / 2) != vec.at(index - 1)){
					vec.at((index - 1) / 2) = vec.at(index - 1);
					update((index - 1) / 2, vec);
				}
			}else{
				if (vec.at((index - 1) / 2) != vec.at(index)){
					vec.at((index - 1) / 2) = vec.at(index);
					update((index - 1) / 2, vec);
				}
			}
		}else{
			vec.at(0) = (vec.at(1) > vec.at(2) ? vec.at(2):vec.at(1));
		}
	}else{
		if (vec.at(index + 1) < vec.at(index)){
			if (vec.at(index / 2) != vec.at(index + 1)){
				vec.at(index / 2) = vec.at(index + 1);
				update(index / 2, vec);
			}
		}else{
			if (vec.at(index / 2) != vec.at(index)){
				vec.at(index / 2) = vec.at(index);
				update(index / 2, vec);
			}
		}
	}
}
int find(int start, int end, const std::vector<int> &vec){
	if (start == end){
		return vec.at(start);
	}else if(start > end){
		return INT_MAX;
	}else{
		int min = find(start >> 1, (end >> 1) - 1, vec);
		if (start % 2 == 0){
			if (min > vec.at(start)){
				min = vec.at(start);
			}
		}
		if (end % 2 == 1){
			if (min > vec.at(end)){
				min = vec.at(end);
			}
		}
		return min;
	}
}
int main(){
	int n, q;
	scanf("%d %d", &n, &q);
	int size = 2;
	while (n != 1){
		n >>= 1;
		size <<= 1;
	}
	std::vector<int> vec(size * 2 - 1, (((1 << 30) - 1) << 1) + 1);
	--size;
	for (auto i = 0; i < q; ++i){
		int com, x, y;
		scanf("%d %d %d", &com, &x, &y);
		if (com == 0){
			vec.at(size + x) = y;
			update(size + x, vec);
		}else{
			printf("%d\n", find(size + x, size + y, vec));
		}
	}
}

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

template<typename T>
T gcd(T a, T b) {
	if( a < b ) swap(a, b);
	
	T r;
	while( r = a % b ) {
		a = b;
		b = r;
	}
	
	return b;
}

int main(void) {
	int n;
	cin >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	int g = a[0];
	for(int i = 1; i < n; ++i) {
		g = gcd(g, a[i]);
	}
	
	if( g > 1 ) {
		cout << "not coprime" << endl;
		return 0;
	}
	
	int maxa = *max_element(a.begin(), a.end());
	
	vector<int> sieve(maxa + 1, -1);
	for(int i = 2; i <= maxa; ++i) {
		if( sieve[i] == -1 ) {
			for(int j = 2 * i; j <= maxa; j += i) {
				if( sieve[j] == -1 ) {
					sieve[j] = i;
				}
			}
		}
	}
	
	for(int i = 1; i <= maxa; ++i) {
		if( sieve[i] == -1 ) sieve[i] = i;
	}
	
	vector<int> cnt(maxa + 1, 0);
	for(int i = 0; i < n; ++i) {
		map<int, int> mp;
		int t = a[i];
		
		while( t > 1 ) {
			mp[sieve[t]]++;
			t /= sieve[t];
		}
		
		mp[t]++;
		
		for(auto& v : mp) {
			cnt[v.first]++;
		}
	}
	
	for(int i = 2; i <= maxa; ++i) {
		if( cnt[i] > 1 ) {
			cout << "setwise coprime" << endl;
			return 0;
		}
	}
	
	cout << "pairwise coprime" << endl;
	
	return 0;
}


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

int main()
{
  int D;
  cin >> D;
  vector<long> C(26);
  for (int i = 0; i < 26; i++) cin >> C.at(i);
  vector<vector<long> > S(D, vector<long>(26));
  for (int i = 0; i < D; i++)
  {
    for (int j = 0; j < 26; j++) cin >> S.at(i).at(j);
  }
  vector<int> T(D);
  for (int i = 0; i < D; i++) cin >> T.at(i);
  vector<int> ans(D+1, 0);
  vector<int> last(26, 0);
  for (int i = 1; i < D+1; i++)
  {
    ans.at(i) += ans.at(i-1);
    last.at(T.at(i-1)-1) = i;
    for (int j = 0; j < 26; j++)
    {
      if (j == T.at(i-1)-1) ans.at(i) += S.at(i-1).at(T.at(i-1)-1);
      else ans.at(i) -= C.at(j) * (i - last.at(j));
    }
    cout << ans.at(i) << endl;
  }
}


Measured memory_bytes: 3720
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        n: usize,
        aa: [usize; n],
    }

    let mut row = 0;
    let mut col = 0;
    let mut board = vec![vec![0; w]; h];

    for (i, a) in aa.into_iter().enumerate() {
        for _ in 0..a {
            board[row][col] = i + 1;
            if row % 2 == 0 {
                if col == w - 1 {
                    row += 1;
                } else {
                    col += 1;
                }
            } else {
                if col == 0 {
                    row += 1;
                } else {
                    col -= 1;
                }
            }
        }
    }

    for line in board {
        let line = line.iter().map(|&x| x.to_string()).collect::<Vec<_>>().join(" ");
        println!("{}", line);
    }
}


Measured memory_bytes: 2224
Var  i:longint;
        n:Int64; 
       s:Ansistring;
Begin
  readln(n);
  str(n,s);
  for i:=2 to length(s) do
      if s[i]<>'9' then 
        begin
          writeln(ord(s[1])-49+(length(s)-1)*9);
          halt;
        end;
   writeln(ord(s[1])-48+(length(s)-1)*9);
End.

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[4];
    rep(i,3){
        cin >> A[i];
    }
    // sort(A,A+3);
    cout << ((A[1]*10+A[2])%4==0 ? "YES" : "NO" ) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	char a[1000];
	int i;
	scanf("%s",a);
	for(i=0;a[i]!='\0';i++){
		if('D'<=a[i]&&a[i]<='Z')a[i]-=3;
		else a[i]+=23;
	}
	printf("%s\n",a);
	return 0;
}



Measured memory_bytes: 2024
N,C,K = map(int,input().split())

T = sorted(int(input()) for _ in range(N))


i = 0
bus = 0
while i < N:
    bus += 1
    c = 0
    limit = T[i]+K
    while c < C and i < N and T[i] <= limit:
        c += 1
        i += 1

print(bus)

Measured memory_bytes: 81484
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define printv(a) {\
    for (auto i : a) cout << i << ' ';\
    cout << '\n';\
}
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define ld long double
#define pll pair<lli,lli>
#define tiii tuple<int,int,int>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define X first
#define Y second
#define oset tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update>
auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);

// AC automaton will help me get AC!
struct AC {
    vector <vector <int>> ch;
    vector <int> cnt, f;
    AC () {extend();}
    void extend() {
        ch.pb(vector <int>(26, 0));
        cnt.pb(0);
    }
    int next(int u, int v) {
        if (!ch[u][v]) {
            ch[u][v] = ch.size();
            extend();
        }
        return ch[u][v];
    }
    void insert(string &s) {
        int now = 0;
        for (char c : s) {
            now = next(now, c - 'a');
        }
        cnt[now]++;
    }
    void build_fail() {
        f.assign(ch.size(), 0);
        queue <int> q;
        for (int i = 0; i < 26; ++i) if (ch[0][i]) q.push(ch[0][i]);
        while (q.size()) {
            int v = q.front(); q.pop();
            for (int i = 0; i < 26; ++i) if (ch[v][i]) {
                    int k = f[v];
                    while (k && !ch[k][i]) k = f[k];
                    if (ch[k][i]) k = ch[k][i];
                    f[ch[v][i]] = k;
                    cnt[ch[v][i]] += cnt[k];
                    q.push(ch[v][i]);
                }
        }
    }
    int match(string &s) {
        int k = 0, ans = 0;
        for (char c : s) {
            while (k && !ch[k][c - 'a']) k = f[k];
            if (ch[k][c - 'a']) k = ch[k][c - 'a'];
            ans += cnt[k];
        }
        return ans;
    }
};

const int mod = 1e9 + 7, x = 864197532, N = 1000087, logN = 17;

struct Dsu {
    int n;
    vector <int> dsu, size;
    Dsu (int n): n(n) {
        dsu.resize(n);
        size.resize(n);
        for (int i = 0; i < n; ++i) {
            dsu[i] = i;
            size[i] = 1;
        }
    }
    int Find(int a) {
        if (dsu[a] == a) return a;
        return dsu[a] = Find(dsu[a]);
    }
    bool Union(int a, int b) {
        int x = Find(a), y = Find(b);
        if (x == y) return false;
        if (size[x] < size[y]) swap(x, y);
        dsu[y] = x;
        size[x] += size[y];
        size[y] = 0;
        return true;
    }
};

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, u, v;
    cin >> n >> m;
    Dsu dsu(n);
    fop (i,0,m) {
        cin >> u >> v, u--, v--;
        dsu.Union(u, v);
    }
    int ans = 0;
    fop (i,0,n) ans = max(ans, dsu.size[i]);
    cout << ans << endl;
}

Measured memory_bytes: 4804
from queue import Queue
H, W  = list(map(int, input().split()))

Ss = []
for i in range(H):
    Ss.append(input())


def bfs(Ss, startX, startY):
    dir = [(1,0), (0, 1), (-1, 0), (0, -1)]

    currentX = startX
    currentY = startY
    queue = Queue()
    visited = set()
    queue.put((currentX, currentY, 0))
    maxDist = 0
    while not queue.empty():
        nextX, nextY, dist = queue.get()
        visited.add((nextX, nextY))
        maxDist = max(maxDist, dist)
        for (dx, dy) in dir:
            y_dy = nextY + dy
            x_dx = nextX + dx
            if y_dy >= 0 and y_dy < len(Ss) and x_dx >= 0 and x_dx < len(Ss[0]):
                if Ss[y_dy][x_dx] != '#':
                    if (x_dx, y_dy) not in visited:
                        queue.put((x_dx, y_dy, dist + 1))
                    visited.add((x_dx, y_dy))
    return maxDist

maxDist = 0
for y in range(H):
    for x in range(W):
        if Ss[y][x] != '#':
            dist = bfs(Ss, x, y)
            maxDist = max(dist, maxDist)
print(maxDist)


Measured memory_bytes: 3952
#include "bits/stdc++.h"
#define lpa(i,a,b) for(int i=a; i<b; ++i)
#define lp(i,n) lpa(i,0,n)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define print_v(v,n) lp(i,n) cout<<v[i]<<' '; cout<<'\n';
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main(int argc, char const *argv[])
{
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(n*a, b);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[0]+list(map(int,input().split()))
b=[0]+list(map(int,input().split()))
for i in range(1,n+1):
  a[i]+=a[i-1]
  b[i]+=b[i-1]
ans=0
for i in range(1,n+1):
  ans=max(ans,a[i]-a[0]+b[n]-b[i-1])
print(ans)

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

vector<double> x[3],y[3]; 
int n;
double mi3(double _a,double _b,double _c){
	return min(_a, min(_b,_c));
}
double ma3(double _a,double _b,double _c){
	return max(_a, max(_b,_c));
}
double area(double t){
	double low_x = 100000000000.0;
	double low_y = 100000000000.0;
	double high_x = - 100000000000.0;
	double high_y = - 100000000000.0;
	if(x[0].size()) {
		low_x = min(low_x, x[0][0]);
		high_x = max(high_x, x[0][x[0].size() - 1]);
	}
	if(y[0].size()) {
		low_y = min(low_y, y[0][0]);
		high_y = max(high_y, y[0][y[0].size() - 1]);
	}
	if(x[1].size()) {
		low_x = min(low_x, x[1][0] - t);
		high_x = max(high_x, x[1][x[1].size() - 1] - t);
	}
	if(y[1].size()) {
		low_y = min(low_y, y[1][0] - t);
		high_y = max(high_y, y[1][y[1].size() - 1] - t);
	}
	if(x[2].size()) {
		low_x = min(low_x, x[2][0] + t);
		high_x = max(high_x, x[2][x[2].size() - 1] + t);
	}
	if(y[2].size()) {
		low_y = min(low_y, y[2][0] + t);
		high_y = max(high_y, y[2][y[2].size() - 1] + t);
	}
	return (high_x - low_x) * (high_y - low_y);
}
double search(double l,double r){
	double it = 1000000;
	while(it --){
		double m1 = l + (r - l) / 3.0;
		double m2 = r - (r - l) / 3.0;
		if(area(m1) < area(m2)) r = m2;
		else l = m1;
	}
	return area(l);
}
signed main(){
	cin >> n;
	for(int i = 1 ; i <= n ; i ++){
		double _x, _y;
		char c;
		cin >> _x >> _y >> c;
		if(c == 'L' || c == 'R'){
			y[0].push_back(_y);
			x[(c == 'L' ? 1: 2)].push_back(_x);
		} else{
			x[0].push_back(_x);
			y[(c == 'D' ? 1: 2)].push_back(_y);
		}
	}
	for(int i = 0 ; i <= 2 ; i ++){
		sort(x[i].begin(),x[i].end());
		sort(y[i].begin(),y[i].end());
	}
	
	cout << setprecision(10) << search(0, 1000000000.0);
	
}

Measured memory_bytes: 4068
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(){
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	ll a,b,c;
	cin>>a>>b>>c;
	cout<<min(b/a,c)<<endl;
}/*『你强归你强，我永不示弱』*/




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	vector<int> num(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> num[i];
	}
	sort(num.begin(), num.end());
	int j = k-1;
	int ans = 1<<30;
	for (int i = 0; j < n; ++i,j++){
		ans = min(ans,num[j]-num[i]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
(N, M) = gets.split.map(&:to_i)

data = []
M.times do
  data << gets.split.map(&:to_i)
end

data.sort_by! do |a|
  a[1]
end

bridge = -1

c = 0
data.each do |a|
  if bridge < a[0]
    bridge = a[1] - 1
    c += 1
  end
end

puts c

Measured memory_bytes: 12664
// ConsoleApplication1.cpp : アプリケーションのエントリ ポイントを定義します。
//

//#include "stdafx.h"

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <set>

//071 B

using namespace std;
int main()
{
	string S;
	cin >> S;
	
	int backets[26] = {};
	for (int i = 0; i < S.size(); i++) {
		backets[S[i] - 'a']++;
	}

	for (int i = 0; i < 26; i++) {
		if (backets[i] == 0) {
			cout << char(i + 'a') << endl;
			return 0;
		}
	}


	cout << "None" << endl;


	return 0;
}



Measured memory_bytes: 512
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();

        Stack<Integer> s1 = new Stack<>();
        Stack<Pair<Integer, Integer>> s2 = new Stack<>();
        int sum = 0;

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '\\') {
                s1.push(i);
            } else if (s.charAt(i) == '/' && !s1.isEmpty()) {
                int j = s1.pop();  // 取栈顶元素

                sum += i - j; // 求总面积

                /* 求各积水处的横截面积 begin */
                int a = i - j;
                while (!s2.isEmpty() && s2.peek().getKey() > j) { // 该横截面上还有其他积水
                    a += s2.pop().getValue();
                }
                s2.push(new Pair<>(j, a));
                /* 求各积水处的横截面积 end */
            }
        }
        // 输出
        System.out.println(sum);
        int size = s2.size();
        System.out.print(size);

        Stack<Integer> s3 = new Stack<>();
        for (int i = 0; i < size; i++) {
            s3.push(s2.pop().getValue());
        }

        for (int i = 0; i < size; i++) {
            System.out.print(" " + s3.pop());
        }
        System.out.println();
    }
}

class Pair<T1 ,T2> {
    private T1 key;
    private T2 value;
    public Pair(T1 key, T2 value) {
        this.key = key;
        this.value = value;
    }

    public T2 getValue() {
        return this.value;
    }

    public T1 getKey() {
        return this.key;
    }
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    vector<int> A(3);
    for (auto &i : A) {
        cin >> i;
    }
    sort(A.begin(), A.end());
    cout << A[0];
    for (int i = 1; i < 3; i++) {
        cout << " " << A[i];
    }
cout << "\n";
    return 0;
}






Measured memory_bytes: 3164