akhauriyash/Code-Regression huggingface dataset:
#include <iostream>                                             
using namespace std;                                            
                                                                
int main(void) {                                                
  int r, c;                                                     
  cin >> r >> c;                                                
  int a[r+1][c+1];                                              
  for (int i=0; i<r+1; i++) {                                   
    for (int j=0; j<c+1; j++) {                                 
      a[i][j] = 0;                                              
    }                                                           
  }                                                             
  for (int i=0; i<r; i++) {                                     
    for (int j=0; j<c; j++) {                                   
      cin >> a[i][j];                                           
      a[r][j] += a[i][j];                                       
      a[i][c] += a[i][j];                                       
      a[r][c] += a[i][j];                                       
    }                                                           
  }                                                             
  for (int i=0; i<r+1; i++) {                                   
    for (int j=0; j<c+1; j++) {                                 
      if (j) {                                                  
        cout << " " << flush;                                   
      }                                                         
      cout << a[i][j] << flush;                                 
    }                                                           
    cout << endl;                                               
  }                                                             
  return 0;                                                     
}                                                               
                                                                
                                                                
                                                

Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main(){
  int N; cin >> N;
  vector<ll> A(N);
  for(int i = 0; i < N; i++)  cin >> A[i];
  sort(A.begin(), A.end());

  ll st = 0, sum = 0;
  for(int i = 0; i < N; i++){
    if(A[i] > sum * 2) st = i;
    sum += A[i];
  }
  cout << N - st << endl;

}


Measured memory_bytes: 1024
L = input()
l = len(L)
dp = [[0]*2 for _ in range(100002)]
# dp[i][smaller]: i桁目までみる　未満なら1
# dp[i][1] : i桁目までみて、a, bどちらもL未満
# dp[i][0] : i桁目までみて、a+b = L
dp[0][0] = 1
mod = 10**9+7

for i in range(l):
  n = L[i]

  if n == '1':
    dp[i+1][0] += dp[i][0]*2 
    dp[i+1][0] %= mod 

    dp[i+1][1] += dp[i][1]*3 + dp[i][0]
    dp[i+1][1] %= mod 

  else:
    dp[i+1][0] += dp[i][0]
    dp[i+1][0] %= mod 

    dp[i+1][1] += dp[i][1]*3
    dp[i+1][1] %= mod

print((dp[l][0]+dp[l][1])%mod)

Measured memory_bytes: 24088
#include<bits/stdc++.h>
using namespace std;
#define maxx 100005
vector<int> g[maxx];
int dp[maxx];
int f(int src)
{
    if(dp[src]!=-1)
        return dp[src];
    int ans=0;
    int flag=0;
    for(auto i : g[src])
    {
        flag=1;
        ans=max(ans,f(i));
    }
    return dp[src]=flag==1?ans+1:0;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        ans=max(ans,f(i));
    cout<<ans;
}


Measured memory_bytes: 11344
#include<iostream>

using namespace std;

int main() {
	int M1, D1;
	int M2, D2;
	cin >> M1 >> D1;
	cin >> M2 >> D2;

	if (M1 + 1 == M2 && D2 == 1) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}




Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int x[5];
    int check = 0;

    for(int i = 0; i < 5; i++){
        scanf("%d\n",&x[i]);
        if(x[i]==0) check = i;
    }
    
    printf("%d\n",check+1);
    return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

int main()
{
    int n, i, a, b;
    n = in();
    vector<int> p(n), q(n), v(n);
    for (i = 0; i < n; i++)
        cin >> p[i];
    for (i = 0; i < n; i++)
        cin >> q[i];
    iota(begin(v), end(v), 1);
    i = 1;
    if(p == q){
        cout << 0 << nl;
        return 0;
    }
    if(v == p){
        a = i;
    }
    if(v == q){
        b = i;
    }
    while (next_permutation(v.begin(), v.end()))
    {
        i++;
        if(v == p){
            a = i;
        }
        if(v == q){
            b = i;
        }
    }
    //cout << a << " " << b << nl;
    cout << abs(a - b) << nl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner (System .in);
        Integer num = scan.nextInt();
        String msg= "No";
    
        if(num > 81){
            System.out.println("No");
        }
        else if (1<=num && num<=9){
            System.out.println("Yes");            
        }
        else{
            for(int i=2;i<=9;i++){
                int d = num % i;
                int e = num / i;
                if(d==0 && 1<=e && e<=9){
                    msg ="Yes";
                    break;                    
                }
            }
            System.out.println(msg);
        }
        scan.close();
    }
}

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

int main() {
  int N,K;
  cin >> N >> K;

  int count = 0;
  while (N > 0) {
  
    if (N / K == 0) {
      break;
    }
    N = N / K;
    count++;
  }
  cout << count+1 << endl;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int m = 0;
		int z = 0;
		int p = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == 0) {
				z++;
			} else if (a[i] > 0) {
				p++;
			} else {
				m++;
			}
		}

		boolean bz = false;
		if (z > 0) {
			bz = true;
		}
		boolean bp = false;
		if (p + m == k) {
			if (m % 2 == 0) {
				bp = true;
			}
		} else if (p + m > k) {
			if (p > 0 || k % 2 == 0) {
				bp = true;
			}
		}

		int mod = 1000000007;
		if (bp) {
			PriorityQueue<Integer> qp = new PriorityQueue<>((o1, o2) -> o2 - o1);
			PriorityQueue<Integer> qm = new PriorityQueue<>();
			for (int i = 0; i < n; i++) {
				if (a[i] > 0) {
					qp.add(a[i]);
				} else {
					qm.add(a[i]);
				}
			}
			qp.add(0);
			qp.add(0);
			qm.add(0);
			qm.add(0);

			long ans = 1;
			for (int i = 0; i < k; i++) {
				Integer np = qp.poll();
				Integer np2 = qp.poll();
				Integer nm = qm.poll();
				Integer nm2 = qm.poll();
				long vp = (long) np * np2;
				long vm = (long) nm * nm2;
				if (vp >= vm || i == k - 1) {
					ans *= np;
					qp.add(np2);
					qm.add(nm);
					qm.add(nm2);
				} else {
					ans *= vm % mod;
					qp.add(np);
					qp.add(np2);
					i++;
				}
				ans %= mod;
			}
			System.out.println(ans);

		} else if (bz) {
			System.out.println(0);

		} else {
			for (int i = 0; i < n; i++) {
				if (a[i] < 0) {
					a[i] = -a[i];
				}
			}
			Arrays.sort(a);
			long ans = 1;
			for (int i = 0; i < k; i++) {
				ans *= a[i];
				ans %= mod;
			}
			ans = mod - ans;
			ans %= mod;
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 68044
n = int(input())
a = list(map(int,input().split()))

ans = [0 for i in range(n+1)]
for i in range(n,0,-1):
    s = 0
    for j in range(i*2,n+1,i): s += ans[j]
    if (s - a[i-1])%2 == 0: pass
    else: ans[i] = 1

print(sum(ans))
anss = []
for i in range(n+1):
    if ans[i] == 1: anss.append(i)
print(*anss)




Measured memory_bytes: 14132
from typing import Dict, List, Optional, Tuple, Union  # noqa: F401


def main(X, Y):
    ans = False
    for a in range(X + 1):
        if 2 * a + 4 * (X - a) == Y:
            ans = True
            break
    print(["No", "Yes"][ans])


if __name__ == "__main__":
    X, Y = map(int, input().split())
    main(X, Y)


Measured memory_bytes: 10268
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void)
{
long H;
long t = 1, ans = 0;
  scanf("%ld", &H);
  while (H > 0) {
    ans += t;
    H /= 2;
    t *= 2;
  }
  printf("%ld\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

int main(){
  ll H, W;
  string str;
  cin >> H >> W;
  bool A[H][W];
  rep(h, H){
    cin >> str;
    rep(w, W) A[h][w] = (str[w] == '#');
  }

  vector<P> darked;
  rep(h, H){
    rep(w, W){
      if(A[h][w]){
        if(h > 0) if(!A[h-1][w]) darked.push_back(P(h-1, w));
        if(w > 0) if(!A[h][w-1]) darked.push_back(P(h, w-1));
        if(h+1 < H) if(!A[h+1][w]) darked.push_back(P(h+1, w));
        if(w+1 < W) if(!A[h][w+1]) darked.push_back(P(h, w+1));
      }
    }
  }
  for(vector<P>::iterator itr = darked.begin(); itr != darked.end(); ++itr){
    A[(*itr).first][(*itr).second] = 1;
  }

  ll ans = 0;
  while(darked.size()){
    vector<P> tmp;
    for(vector<P>::iterator itr = darked.begin(); itr != darked.end(); ++itr) {
      ll h = (*itr).first;
      ll w = (*itr).second;
      if(h > 0) if(!A[h-1][w]){
        tmp.push_back(P(h-1, w));
        A[h-1][w] = 1;
      }
      if(w > 0) if(!A[h][w-1]){
        tmp.push_back(P(h, w-1));
        A[h][w-1] = 1;
      }
      if(h+1 < H) if(!A[h+1][w]){
        tmp.push_back(P(h+1, w));
        A[h+1][w] = 1;
      }
      if(w+1 < W) if(!A[h][w+1]){
        tmp.push_back(P(h, w+1));
        A[h][w+1] = 1;
      }
    }
    ans++;
    darked = tmp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 22376
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)n; ++i)
using ll = long long;
using namespace std;
static const int MAX = 100000;

int main(){
  int n; ll a[MAX];
  cin >> n;
  rep(i, n) cin >> a[i];
  
  if(n == 2){
    cout << a[0] << " " << a[1] << endl;
    return 0;
  }
  
  ll max_a = a[0];
  rep(i, n) max_a = max(max_a, a[i]);
  
  const ll halfmax_a = max_a / 2;
  int good_a = a[0];
  rep(i, n){
    static ll min_dif = abs(halfmax_a - a[0]);
    if(min_dif > abs(halfmax_a - a[i])){
      min_dif = abs(halfmax_a - a[i]);
      good_a = a[i];
    }
  }
  
  cout << max_a << " " << good_a << endl;
  return 0;
}

Measured memory_bytes: 1024
main :: IO ()
main = do
  (n:m:x:y:_) <- fmap (map read . words) getLine :: IO [Int]
  xs <- fmap (map read . words) getLine :: IO [Int]
  ys <- fmap (map read . words) getLine :: IO [Int]
  putStrLn $ if war (x:xs) (y:ys)
             then "War"
             else "No War"

war :: [Int] -> [Int] -> Bool
war xs ys = (maximum xs) >= (minimum ys)


Measured memory_bytes: 1020
s = gets.split
w = s[0].to_i
h = s[1].to_i
x = s[2].to_i
y = s[3].to_i
r = s[4].to_i

if x+r <= w && x-r >= 0 && y+r <= h && y-r >=0 then
puts "Yes"
else
puts "No"
end




Measured memory_bytes: 6868
#include<algorithm>
#include<cstdio>
using namespace std;
inline void in(int &s){
	s=0;char c=getchar();
	while(c<'0' || c>'9'){
		c=getchar();
	}
	while(c>='0' && c<='9'){
		s=(s<<1)+(s<<3)+c-'0';
		c=getchar();
	}
}
int n,m,z,ans;
long long sum;
bool ok=1;
struct xx{
	int a,b;
}s[200002];
int cmp(xx x,xx y){
	return x.a>y.a;
}
int main(){
	in(n);in(m);
	for(int i=0;i<n;++i){
		in(s[z++].a);s[z].b=1;in(s[z++].a);
	}
	sort(s,s+z,cmp);
	for(int i=0;i<z;++i){
		if(s[i].b){
			m-=s[i].a;++ans;
		}
		else{
			if(m%s[i].a==0) ans+=m/s[i].a;
			else ans+=m/s[i].a+1;
			printf("%d\n",ans);break;
		}
		if(m<1){
			printf("%d\n",ans);break;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

int main()
{
    ll n=in();
    vector<ll>h(n);REP(i,n)h[i]=in();
    ll minh=-INFLL,ans=0;
    REP(i,n){
        if(h[i]>=minh){
            ++ans;
            minh=h[i];
        }
    }
    cout<<ans<<endl;
}

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

PPP = list(map(int, input().split()))

ans = 0
for i in range(1, N-1):
    if (PPP[i] >= PPP[i-1] and PPP[i+1] > PPP[i]) or (PPP[i] >= PPP[i+1] and PPP[i-1] > PPP[i]):
        ans += 1

print(ans)


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


void solve(long long N, long long K, std::vector<long long> A){
    map<ll, ll> m;
    vector<ll> cs;
    cs.push_back(0);
    m[0]++;
    ll ans = 0;
    REP(i, N){
        cs.push_back(A.at(i) + cs.back());
        if(i + 1 - K >= 0){
            m[(cs.at(i + 1 - K) - (i + 1 - K)) % K]--;
        }
        ll tmp = (cs.back() - (i + 1)) % K;
        ans += m[tmp];
        m[tmp]++;
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 15856
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 




signed main(){
    FASTER;
        int r;cin>>r;
        cout<<r*r;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
  int h, w; cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;++i) cin >> s[i];
  

  vector<vector<int> > up(h, vector<int>(w,0));
  vector<vector<int> > down(h, vector<int>(w,0));
  vector<vector<int> > left(h, vector<int>(w,0));
  vector<vector<int> > right(h, vector<int>(w,0));

  // left
  for(int i=0;i<h;++i) {
    if(s[i][0] == '.') left[i][0] = 1;
    for(int j=1;j<w;++j) {
      if (s[i][j] == '.') {
        left[i][j] = left[i][j-1]+1;
      }
    }
  }
  // right
  for(int i=0;i<h;++i) {
    if(s[i][w-1] == '.') right[i][w-1] = 1;
    for(int j=w-2;j>=0;--j) {
      if (s[i][j] == '.') {
        right[i][j] = right[i][j+1]+1;
      }
    }
  }
  // up
  for(int j=0;j<w;++j) {
    if(s[0][j] == '.') up[0][j] = 1;
    for(int i=1;i<h;++i) {
      if(s[i][j] == '.') {
        up[i][j] = up[i-1][j] +1;
      }
    }
  }
  // down
  for(int j=0;j<w;++j) {
    if(s[h-1][j] == '.') down[h-1][j] = 1;
    for(int i=h-2;i>=0;--i) {
      if(s[i][j] == '.') {
        down[i][j] = down[i+1][j] +1;
      }
    }
  }
  int z = 0;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j) {
      if(s[i][j]=='.') {
        z = max(z, up[i][j]+down[i][j]+left[i][j]+right[i][j]-3);
      }
    }
  }
  cout << z << endl;

  return 0;
}



Measured memory_bytes: 67200
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

struct weighted_UnionFind
{
    vector<int> rnk, par, diff_weight;

    weighted_UnionFind(int N) : par(N), rnk(N), diff_weight(N)
    {
        for (int i = 0; i < N; ++i)
        {
            rnk[i] = 1;
            par[i] = i;
            diff_weight[i] = 0;
        }
    }
    int root(int x)
    {
        if (par[x] == x)
        {
            return x;
        }
        else
        {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
    int weight(int x)
    {
        root(x);
        return diff_weight[x];
    }
    void unite(int x, int y, int w)
    {
        w += weight(x);
        w -= weight(y);

        x = root(x);
        y = root(y);

        if (x == y)
            return;

        if (rnk[x] < rnk[y])
        {
            swap(x, y);
            w = -w;
        }

        if (rnk[x] == rnk[y])
            rnk[x]++;
        par[y] = x;
        diff_weight[y] = w;
    }

    int diff(int x, int y)
    {
        return weight(y) - weight(x);
    }
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
};
int main(void)
{
    int N, M;
    cin >> N >> M;
    weighted_UnionFind uf(N);
    for (int i = 0; i < M; ++i)
    {
        int L, R, D;
        cin >> L >> R >> D;
        L--;
        R--;
        if (uf.same(L, R))
        {
            int dif = uf.diff(L, R);
            if (dif != D)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            uf.unite(L, R, D);
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main(){
  int N;
  int cnt=0;
  int endA=0;
  int startB=0;
  int flag=0;
  string S;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>S;
    for(int j=0;j<S.length()-1;j++){
      if((S.at(j)=='A')&&(S.at(j+1)=='B')){
        cnt++;
      }
    }
    if((S.at(0)=='B')&&(S.at(S.length()-1)=='A')){
      flag++;
    }
    else if(S.at(0)=='B'){
      startB++;
    }
    else if(S.at(S.length()-1)=='A'){
      endA++;
    }

  }
  if(flag==0){
    cout<<cnt+min(startB,endA)<<endl;
    return 0;
  }
  if(startB+endA==0){
    cout<<cnt+flag-1<<endl;
    return 0;
  }
  cout<<cnt+flag+min(startB,endA)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e6;
int dp[MN];
	string s;
	int n;
int main() {

	cin>>n;
	cin>>s;
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		dp[i+1] = max(dp[i], dp[i+1]);
		if(i + 2 < n && s[i] == '1' && s[i+1] == '0' && s[i+2] == '1') {
			int pos = i;
			while(pos > 0) {
				if(s[pos] != '1') {
					break;
				}
				--pos;
			}
			if(s[pos] != '1') ++pos;
			dp[i+2+1] = max(dp[i+2+1], dp[pos+1-1] + i - pos + 1);
			if(i - pos +1 > 1) {
				dp[i+2+1] = max(dp[i+2+1], dp[pos+1-1+1] + i - pos);
			}
			pos = i+2;
			while(pos+1 < n) {
				if(s[pos] != '1') break;
				++pos;
			}
			if(s[pos] != '1') --pos;
			dp[pos+1] = max(dp[pos+1], dp[i] + pos-(i+2)+1);
			if(pos - (i+2) + 1 > 1) {
				dp[pos] = max(dp[pos], dp[i] + pos-(i+2));

			 }
		}
	}
	cout<<dp[n]<<'\n';
}


Measured memory_bytes: 2820
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    ll cnt = 0;
    for(auto c:S){
        if(c == 'R'){
            cnt++;
            res = max(res,cnt);
        }else{
            cnt = 0;
        }
    }
    res = max(res,cnt);
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 3648
import math
n,a0,b0 = map(int,input().split())
a = min(a0,b0)
b = max(a0,b0)
ans = 0
if abs(a-b) % 2 == 0:
    ans = abs(a-b)//2
else:
    if (a-1) < (n-b):
        ans = (a-1)+(b-a+2)//2
    else:
        ans = (n-b)+(b-a+1)//2

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack> 
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define ULL unsigned long long
#define N 1000100
#define M 5010
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define X first
#define Y second
using namespace std;
char st[10];
int main(){
	scanf("%s",st);
	int len = strlen(st);
	int flag = 0;
	for (int i = 0; i < len - 1; i ++) if (st[i] == 'A' && st[i + 1] == 'C'){
		flag = 1;
		break;
	}
	if (flag) printf("Yes\n");
	else printf("No\n");
}

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

int main(){
    int N, A[200000];
    int64_t K;
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> A[i];

    int nxt[200001], last[200001];
    nxt[N] = N;
    for(int i=0; i<=200000; i++) last[i] = N;
    for(int i=N-1; i>=0; i--){
        nxt[i] = last[A[i]];
        last[A[i]] = i;
    }

    int term[200001];
    term[N] = N;
    for(int i=N-1; i>=0; i--){
        if(nxt[i] == N){
            term[i] = i;
        }else{
            term[i] = term[nxt[i]+1];
        }
    }

    int pos = N, period = 0;
    vector<int> result = {N};
    while(true){
        period++;
        pos = (pos == N ? 0 : last[A[pos]] + 1);
        pos = term[pos];
        if(pos == N) break;
        result.push_back(pos);
    }

    K %= period;
    int start = result[K];
    vector<int> ans;
    set<int> st;
    for(int i=start; i<N; i++){
        if(st.count(A[i])){
            while(st.count(A[i])){
                st.erase(ans.back());
                ans.pop_back();
            }
        }else{
            ans.push_back(A[i]);
            st.insert(A[i]);
        }
    }

    for(int a : ans) cout << a << " ";
    cout << endl;
    return 0;
}


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

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ').Select(x => int.Parse(x)).ToList();

            var n = list[0];
            var k = list[1];

            if (k == 1){
                Console.WriteLine("0");
                return;
            }

            var remain = n - k;

            Console.WriteLine(remain.ToString());
        }
    }
}


Measured memory_bytes: 11220
import sys
from itertools import accumulate
from collections import Counter


def main():
    n = sys.stdin.readline()
    print(sum([(n*(n-1))//2 for n in [n for n in Counter(list(accumulate([0]+list(map(int, sys.stdin.readline().rstrip().split()))))).values() if n > 1]]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 33932
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll a,b,c,count=0;
    cin>>a>>b>>c;
    vector<ll> v={a,b,c};
    sort(ALL(v));
    a=v[0],b=v[1],c=v[2];
    while(b<c){
        a++;
        b++;
        count++;
    }
    if((c-a)%2==0){
        while(a<c){
            a+=2;
            count++;
        }
    }else{
        b++;
        c++;
        count++;
        while(a<c){
            a+=2;
            count++;
        }
    }
    cout<<count;
    return 0;
}


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

int main()
{
    int A[3], v, i, j;
    for (i = 0; i < 3; i++) cin >> A[i];
    for (i = 1; i < 3; i++)
    {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v )
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
    }
    for (i = 0; i < 3; i++)
    {
        cout << A[i];
        if (i < 2) cout << " ";
        if (i == 2) cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) return b; return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
#define debug2(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...);}
#define time__(d) for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second; debug2("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;

void getac(int T) {
    for (int i = 0; i < 5; i++) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << i + 1 << '\n';
        }
    }
}
int  main()
{

    fastio;
    int t = 1;
    if (takeTestCases) cin >> t;
    int t_t = 1;
    while (t--) {
        if (printCaseNo)
        case (t_t);
        getac(t_t);
        t_t++;
    }
    cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 3800
a, b, k = map(int, input().split())
while k > 0:
    if a > 0:
        if a <= k:
            k -= a
            a = 0
        else:
            a -= k
            k = 0
    elif b > 0:
        if b <= k:
            k -= a
            b = 0
        else:
            b -= k
            k = 0
    else:
        k = 0
print(a, b)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <algorithm>
using namespace std;


vector<vector<int>> g;
vector<int> degree;
vector<int> dp;
vector<int> vis;
int mx = 0;
void dfs(int v) {
	assert(vis[v] == 0);
	vis[v] = 1;
	for (int e : g[v]) {
		dp[e] = max(dp[e], dp[v] + 1);
		mx = max(mx, dp[e]);
		degree[e]--;
		if (degree[e] == 0) {
			dfs(e);
		}
	}
	return;
}

int main(){
	int n, m;
	cin >> n >> m;
	g.resize(n);
	degree.resize(n);
	dp.resize(n);
	vis.resize(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		degree[b]++;
	}
	for (int i = 0; i < n; i++) {
		if (vis[i] == 0 && degree[i] == 0) {
			dfs(i);
		}
	}
	cout << mx;
}


Measured memory_bytes: 12464
N = int(input())
A = [int(input()) for _ in range(N)]

dict = {}

for a in A:
    if a not in dict.keys():
        dict[a] = 1
    else:
        dict[a] += 1

cnt = 0
for v in dict.values():
    if v % 2 == 1:
        cnt += 1

print(cnt)

Measured memory_bytes: 16268
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  char a,b;
  cin>>a>>b;
  string ans="<";
  if(a>b)ans=">";
  if(a==b)ans="=";
  cout(ans);
  return 0;
}

Measured memory_bytes: 125696
using System;
using System.Collections.Generic;

class program
{
    static void Main()
    {
        List<int> Sdate = new List<int> { }; 

        Sdate = Dateinp();

        int[,] Date = DateArray(Sdate);

        for (int i = 0; i < Date.GetLength(0) - 1; i++)
        {
            if ((Date[i, 0] == -1) || (Date[i, 1] == -1))
            {
                Console.WriteLine("F");
            }
            else
            {
                if ((Date[i, 0] + Date[i, 1]) >= 80)
                {
                    Console.WriteLine("A");
                }

                else
                {
                    if ((Date[i, 0] + Date[i, 1]) >= 65)
                    {
                        Console.WriteLine("B");
                    }
                    else
                    {
                        if (Date[i, 0] + Date[i, 1] >= 50)
                        {
                            Console.WriteLine("C");
                        }

                        else
                        {
                            if (Date[i, 0] + Date[i, 1] >= 30)
                            {
                                if (Date[i, 2] >= 50)
                                {
                                    Console.WriteLine("C");
                                }
                                else
                                {
                                    Console.WriteLine("D");
                                }
                            }
                            else
                            {
                                Console.WriteLine("F");
                            }
                        }
                    }
                }

            }

        }
         
    }

    static int[,] DateArray(List<int> list)
    {
        int length = list.Count;

        int Row = length / 3;

        int[,] datearray = new int[Row,3];

        int count = 0;

        for (int i = 0;i<Row; i++)
        {
            for (int j=0;j<3; j++)
            {
                datearray[i, j] = list[count];
                count += 1;
            }
        }

        return datearray;
                
    }

    static List<int> Dateinp()
    {
        List<int> Date = new List<int> { };

        while (true)
        {

            int x;
            int y;
            int z;
            string[] str = Console.ReadLine().Split(' ');

            x = int.Parse(str[0]);
            y = int.Parse(str[1]);
            z = int.Parse(str[2]);

            Date.Add(x);
            Date.Add(y);
            Date.Add(z);

            int End = x + y + z;

            if (End == -3)
                break;
        }

        return Date;
    } 
}

Measured memory_bytes: 8860
/* Max heap */
#include <stdio.h>
#include <stdlib.h>

void maxHeapify(int heap[], int i);
void buildMaxHeap(int heap[]);
void swap(int *, int *);

int H;      /* ヒープサイズ */

int main()
{
  int *heap, i;

  /* ヒープ用の領域を動的に確保 */
  scanf("%d", &H);
  heap = (int *)malloc( sizeof(int) * (H+1) );

  /* ヒープの各節点の値を読込む */
  for( i = 1; i<=H; i++ )
    scanf("%d", &heap[i]);
  
  /* 最大ヒープを作成 */
  buildMaxHeap(heap);

  /* 最大ヒープの各節点の値を節点の番号が１からHに向って順番に出力 */
  for( i = 1; i<=H; i++ )
    printf(" %d", heap[i]);
  printf("\n");
  
  return 0;
}


/* 配列heapを最大ヒープに変換する関数 */
void buildMaxHeap(int heap[])
{
  int i;

  for( i = H/2; i>=1; i-- )
    maxHeapify(heap, i);
}


/* heap[i]を根ノードとする部分木を最大ヒープに変換する関数 */
void maxHeapify(int heap[], int i)
{
  int l = i*2, r = i*2+1, largest;

  /* 根ノードheap[i]、左の子、右の子の中から最大のものを求める */
  if( l<=H && heap[i] < heap[l] )
    largest = l;
  else
    largest = i;
  if( r<=H && heap[largest] < heap[r] )
    largest = r;

  if( i != largest )
    {
      swap(&heap[i], &heap[largest]);
      maxHeapify(heap, largest);
    }
}


/* int型変数 a,b を交換する関数 */
void swap(int *a, int *b)
{
  int tmp;

  tmp = *a;
  *a  = *b;
  *b  = tmp;
}



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

int main(void) {
	int n;
	scanf("%d", &n);
	long long int a[n];
	int i;
	long long int element = 0;
	for (i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	if (n == 1) {
		printf("%lld\n", a[0]);
	} else {
		element = gcd(a[0], a[1]);
		if (n == 2) {
			printf("%lld\n", element);
		} else {
			for (i = 2; i < n; i++) {
				element = gcd(element, a[i]);
			}
		}
	}
	int count = 0;
	while (1) {
		if (element % 2 == 0 && element > 0) {
			element /= 2;
			count++;
		} else {
			break;
		}
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 128
a,b=map(int,input().split())
s=list(input())
if s[a]=='-':
    c=0
    for i in range(0,a+b+1):
        if s[i].isdecimal()==True:
            c=c+1
    if c==a+b:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int N, R = 0, B = 0;
    string s;
    cin >> N >> s;
    for (int i = 0; i < N; i++){
        if (s.at(i) == 'R'){
            R++;
        }
        else {
            B++;
        }
    }
    if (R > B){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



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

int main() {
int n;
string s;
cin>>n>>s;
int ans=0;
int tmp=0;
for(int i=0;i<n;i++){
  if(s[i]=='I') tmp++;
  if(s[i]=='D') tmp--;
  ans=max(ans,tmp);

}
cout<<ans<<endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ll H; cin >> H;
    int x = (int) floor(log2(H));
    ll sum = 0;
    for (int i = 0; i < x+1; ++i) {sum += pow(2, i);}
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NOT -1

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

Node Tree[MAX];
int num,Depth[MAX],Height[MAX];
int setHeight(int);
void setDepth(int u, int depth)
{
  if(u==NOT)return;
  Depth[u]=depth;
  setDepth(Tree[u].left,depth+1);
  setDepth(Tree[u].right,depth+1);
}

int setHeight(int u)
{
  int h1=0,h2=0;
  if(Tree[u].left != NOT)
  h1 = setHeight(Tree[u].left)+1;
  if(Tree[u].right != NOT)
  h2 = setHeight(Tree[u].right)+1;
  return Height[u]=(h1>h2 ? h1:h2);
}

int getSibling(int u)
{
  if(Tree[u].parent == NOT) return NOT;
  if(Tree[Tree[u].parent].left != u && Tree[Tree[u].parent].left != NOT)
    return Tree[Tree[u].parent].left;
  if(Tree[Tree[u].parent].right != u && Tree[Tree[u].parent].right != NOT)
    return Tree[Tree[u].parent].right;
  return NOT;
}

void print(int u)
{
  printf("node %d: ",u);
  printf("parent = %d, ",Tree[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int degree =0;
  if(Tree[u].left != NOT) degree++;
  if(Tree[u].right != NOT) degree++;
  printf("degree = %d, ",degree);
  printf("depth = %d, ",Depth[u]);
  printf("height = %d, ",Height[u]);

  if(Tree[u].parent == NOT) printf("root\n");
  else if (Tree[u].left == NOT && Tree[u].right == NOT) printf("leaf\n");
  else printf("internal node\n");
}

int main()
{
  int i;
  int par,left,right,root =0;
  scanf("%d",&num);

  for(i=0; i<num; i++)Tree[i].parent =NOT;

  for(i=0; i<num; i++)
    {
      scanf("%d %d %d",&par,&left,&right);
      Tree[par].left=left;
      Tree[par].right=right;
      if(left != NOT) Tree[left].parent = par;
      if(right != NOT) Tree[right].parent = par;
    }

  for(i=0;i<num;i++)if(Tree[i].parent == NOT)root = i;

  setDepth(root,0);
  setHeight(root);
  for(i=0;i<num;i++) print(i);
  return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll N,K;
ll a[102];

ll memo[100005];   // -1:負け , 1:勝ち

int dfs(int num){
    if(memo[num]) return memo[num];
    if(num < a[0]){
        return memo[num] = -1;
    }

    for(int i=0;i<N;i++){
        if(num-a[i]>=0 and dfs(num - a[i])==-1){
            return memo[num] = 1;
        }
    }
    return memo[num] = -1;
}

int main(){
    cin >> N >> K;
    rep(i,N) cin >> a[i];

    int v = dfs(K);
    if(v==1){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
}


Measured memory_bytes: 4096
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
void dfs (int cur, int par, int d, const vector<vector<int>>& g, vector<int>& dist) {
  dist[cur] = d;
  for (int child : g[cur]) if (child != par) {
    dfs (child, cur, d + 1, g, dist);
  }
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int t, a;
  cin >> t >> a;
  --t;
  --a;
  vector<vector<int>> g(n);
  for (int i = 0; i + 1 < n; i++) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  if (t == a) {
    cout << 0 << '\n';
    return 0;
  }
  vector<int> distFromt(n);
  dfs (t, -1, 0, g, distFromt);
  vector<int> distFroma(n);
  dfs (a, -1, 0, g, distFroma);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (distFromt[i] <= distFroma[i]) {
      ans = max(ans, distFroma[i] - 1);
    }
  }
  cout << ans << '\n';
  return 0;
}

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

int main(){
  string s,a,b;
  int c,d;
  cin >> s;
  d=0;
  c=s.size();
  while(c>=2){
    a=s.substr(0,1);
    b=s.substr(c-1,1);
    if(a!=b){
      d+=1;
    }
    s.erase(0,1);
    s.erase(c-2,1);
    c=s.size();
  }
  cout << d;
}

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

int main() {
    
    ll N;
    cin >> N;

    map<int, char> M;
    for(int i = 0; i < 26; i++){
       char a = 'a';
       M[i] = a + i;
    }

    vector<long long> V;
    long long Num = N;
    while(Num > 0){
       V.push_back((Num - 1) % 26);
       Num -= 1;
       Num /= 26;
    }
      reverse(V.begin(), V.end());
    for(auto v:V){
       cout << M[v];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;

int main(){
    int d;
    cin >> d;
    if (d == 25) cout << "Christmas" << endl;
    else if (d == 24) cout << "Christmas Eve" << endl;
    else if (d == 23) cout << "Christmas Eve Eve" << endl;
    else if (d == 22) cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


vector<long> noborikata;

const long div_ = 1000000007;

long noboru(long start, long finish) {
	long a = finish - start;

	if (a <= noborikata.size() - 1) {
		return noborikata[a];
	}
	else {
		for (int i = noborikata.size(); i <= a; i++) {
			noborikata.push_back((noborikata[i - 2] + noborikata[i - 1]) % div_);
		}
		return noborikata[a];
	}
}

int main()
{

	long n, m;
	cin >> n >> m;
	long now = 0;
	long answer = 1;
	long mae_a = -1;

	noborikata.push_back(1);
	noborikata.push_back(1);

	for (long i = 0; i < m; i++) {
		long a;
		cin >> a;
		if (a - mae_a <= 1) {
			cout << 0 << endl;
			return 0;
		}
		answer = (answer * noboru(now, a-1)) % div_;
		now = a + 1;
		mae_a = a;
	}
	
	answer = (answer * noboru(now, n)) % div_;

	cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1400
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
query = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = mapint()
    query[a-1].append((b-1, c))
    query[b-1].append((a-1, c))

Q, K = mapint()
from collections import deque
stack = deque([(K-1, 0, -1)])
dist = [0]*N
while stack:
    now, cnt, per = stack.pop()
    lis = query[now]
    dist[now] = cnt
    for nx, c in lis:
        if nx==per:
            continue
        if c!=0:
            stack.append((nx, cnt+c, now))

for _ in range(Q):
    x, y = mapint()
    print(dist[x-1]+dist[y-1])

Measured memory_bytes: 50424
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
k,n = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]

a.sort()
a.append(a[0]+k) # 1番目の家とn番目の家の間の距離

d = 0
for i in range(n): # 1番目の家と2番目の家、2番目の家と3番目の家、、、n-1番目の家とn番目の家の間の距離
    d = max(d, a[i+1]-a[i]) # 一番離れている家はどれか

print(k-d) # 一番離れている家を最初と最後に行くことにするのが最短距離

Measured memory_bytes: 24908