akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	int X,Y;
	cin>>X>>Y;
	cout<<(X+Y/2)<<endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

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



int main(){
    int m;
    cin >> m;
    cout << 24+24-m << endl;
}


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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define mod 1000000007
#define INF 100000000
#define fk first
#define sv second

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

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

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

  while (cin >> n, n){
    int ct = 0;
    if (n % 1111 == 0){
      cout << "NA\n";
      continue;
    }
    
    while (n != 6174){
      int l, s, num[4];
      REP(i, 4){
        num[i] = n % 10;
        n /= 10;
      }
      sort(num, num + 4);
      l = s = 0;
      REP(i, 4){
        l = l * 10 + num[3 - i];
        s = s * 10 + num[i];
      }
      n = l - s;
      ct++;
    }
    cout << ct << endl;
  }
}

Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <atcoder/twosat>
using namespace std;
using namespace atcoder;

int main() {
	int N, D;
	cin >> N >> D;
	vector<int> X(N), Y(N);
	for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];
	two_sat ts(N);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (abs(X[i] - X[j]) < D) ts.add_clause(i, false, j, false);
			if (abs(X[i] - Y[j]) < D) ts.add_clause(i, false, j, true);
			if (abs(Y[i] - X[j]) < D) ts.add_clause(i, true, j, false);
			if (abs(Y[i] - Y[j]) < D) ts.add_clause(i, true, j, true);
		}
	}
	bool ans = ts.satisfiable();
	cout << (ans ? "Yes" : "No") << endl;
	if (ans) {
		vector<bool> b = ts.answer();
		for (int i = 0; i < N; i++) cout << (b[i] ? X[i] : Y[i]) << endl;
	}
}


Measured memory_bytes: 3688
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define fr(i,x,y) for(int i=(x);i<=(y);i++)
#define rf(i,x,y) for(int i=(x);i>=(y);i--)
#define frl(i,x,y) for(int i=(x);i<(y);i++)
#define N 405
#define ll long long
#define mod 998244353
int n, a[N], b[N];
int f[N][N];
int Pow(int a, int k)
{
	if (!k)
		return 1;
	int p = Pow(a, k / 2);
	if (k & 1)
		return (ll)p * p % mod * a % mod;
	return (ll)p * p % mod;
}
int fac[N], inv[N];
void Add(int &x, int y)
{
	x += y;
	if (x >= mod)
		x -= mod;
}
int main()
{
	fac[0] = 1;
    for (int i = 1; i <= 400; i++)
		fac[i] = (ll)fac[i - 1] * i % mod;
	inv[400] = Pow(fac[400], mod - 2);
	for (int i = 400; i >= 1; i--)
		inv[i - 1] = (ll)inv[i] * i % mod;
    scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &a[i], &b[i]);
    int S = 0;
	for (int i = 1; i <= n; i++)
		S += a[i];
    f[0][0] = mod - 1;
	for (int i = 1; i <= n; i++)
		for (int k = 400; k >= 0; k--)
			for (int j = 0; j <= 400; j++)
				for (int x = 0; x < b[i]; x++)
					if (f[j][k])
						Add(f[j + x][k + a[i]], mod - (ll)f[j][k] * Pow(a[i], x) % mod * inv[x] % mod);
	int ans = 0;
	for (int j = 0; j <= 400; j++)
		for (int k = 1; k <= 400; k++)
			Add(ans, (ll)fac[j] * f[j][k] % mod * Pow(k, mod - j - 1) % mod * Pow(k, mod - 2) % mod * S % mod);
	printf("%d\n", ans);
}

Measured memory_bytes: 896
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#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 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;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

vector<ll>Dijkstra(const vector<vector<pair<ll, ll>>> &edge, ll start = 0)
{
    vector<ll>dist(edge.size(), INFLL);
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> node_queue;
    dist[start] = 0; node_queue.emplace(0, start);
    while (!node_queue.empty()) {
        ll tpn_dist = node_queue.top().first, tpn_index = node_queue.top().second; node_queue.pop();
        if (dist[tpn_index] >= tpn_dist) {
            for (auto to : edge[tpn_index]) {
                ll dst_index = to.first, dst_dist = to.second;
                if (dist[dst_index] > dist[tpn_index] + dst_dist) {
                    dist[dst_index] = dist[tpn_index] + dst_dist;
                    node_queue.emplace(dist[dst_index], dst_index);
                }
            }
        }
    }
    return dist;
}
int main()
{
    ll n = in();
    vector<vector<pair<ll, ll>>>edge(n);
    REP(i, n - 1) {
        ll u, v, w;
        scanf("%lld %lld %lld", &u, &v, &w);
        edge[u - 1].emplace_back(v - 1, w);
        edge[v - 1].emplace_back(u - 1, w);
    }
    auto res = Dijkstra(edge);
    REP(i, n)cout << res[i] % 2 << endl;
}

Measured memory_bytes: 8704
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static void WriteLine(object obj) {
#if DEBUG
        Debug.WriteLine(obj.ToString());
#else
        Console.WriteLine(obj.ToString());
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var q     = int.Parse(spl[1]);
        var s = input.ReadLine();

        var points = new int[n];
        var sum = 0;
        for(int i=1; i<n; i++) {
            if(s[i-1]=='A' && s[i] == 'C') {
                sum++;
            }
            points[i] = sum;
        }

        for(int i=0; i<q; i++) {
            spl   = input.ReadLine().Split(' ');
            var l     = int.Parse(spl[0]);
            var r     = int.Parse(spl[1]);

            WriteLine(points[r - 1] - points[l - 1]);
        }
        return null;
    }
}

Measured memory_bytes: 16324
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n;
    cin  >> n;
    string str;
    cin >> str;
    vector <ll> R;
    vector <ll> G;
    vector <ll> B;
    for(ll i=0;str[i]!='\0';i++)
    {
        if(str[i]=='R')
        {
            R.push_back(i);
        }
        else if(str[i]=='G')
        {
            G.push_back(i);
        }

        else if(str[i]=='B')
        {
            B.push_back(i);
        }
    }
    long long int R_size=R.size();
    long long int G_size=G.size();
    long long int B_size=B.size();
    long long int arr[B_size];
    long long int ans=R_size*G_size*B_size;
//    long long int minus=0;
    vector<ll>check;
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            int k = 2*j - i;
            if(k < n && str[i] != str[j] && str[j] != str[k] && str[i] != str[k])
                ans--;

        }

    }
    //ans-=minus;
    //cout << minus<<"\n";
    cout << ans;
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
map<string,int> F,G,H;
string s;
int f(string);
int g(string);
int h(string);
int dp(string);

int main(){
	cin>>s;
	cout<<dp(s)<<endl;

	return 0;
}

int f(string s){
	if(F[s]) return F[s];
	int res=0,len=s.size();
	int r=s[0]-'0'+1;
	for(int i=1;i<len;i++){
		(res+=1ll*r*(g(s.substr(i))+h(s.substr(i)))%mod)%=mod;
		if(s[i]=='1') r=2*r%mod;
	}
	(res+=r)%=mod;
	return F[s]=res;
}

int g(string s){
	if(G[s]) return G[s];
	int res=0,len=s.size();
	if(len==1) return 0;
	for(int i=1;i<len;i++) (res+=1ll*h(s.substr(0,i))*dp(s.substr(i))%mod)%=mod;
	return G[s]=res;
}

int h(string s){
	if(H[s]) return H[s];
	int res=0,len=s.size();
	if(len==1) return 0;
	for(int i=1;i<len;i++){
		if(len%i==0){
			string t;t.empty();
			for(int j=1;j<=i;j++){
				int flag=1;
				for(int k=0;k<len/i;k++) if(s[k*i+j-1]=='0') flag=0;
				if(flag) t+='1';else t+='0';
			}
			(res+=dp(t))%=mod;
		}
	}
	return H[s]=res;
}

int dp(string s){
	int res=0;
	(res+=f(s))%=mod;
	(res+=g(s))%=mod;
	(res+=h(s))%=mod;
	return res;
}

Measured memory_bytes: 16768
#include<stdio.h>
int main()
{
	int t,n,s,f;
	while(scanf("%d",&t),t)
	{
		for(scanf("%d",&n);n--;)
		{
			scanf("%d%d",&s,&f);
			t+=s-f;
		}
		if(t<=0)puts("OK");
		else printf("%d\n",t);
	}
	return 0;
}

Measured memory_bytes: 1040
import java.util.Scanner;

public class Main{

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

        // input
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        // answer
        System.out.println(Math.max(0, c - (a - b)));

    }
}

Measured memory_bytes: 23380
#include<stdio.h>
int main()
{
int a[1000],i,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=n-1;i>=1;i--)
{
printf("%d ",a[i]);
}
printf("%d\n",a[0]);
return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define ll           long long int
#define pb           push_back
#define F            first
#define S            second
using namespace std;
	int main(){
        int t,n,a,b,c,ans=0;
        cin>>n;
        for( a=1;a<n;a++){
            for( b=1;a*b<n;b++){
                ans++;
            }
        }
        cout<<ans<<endl;
	}


Measured memory_bytes: 3624
#include <iostream>

#include<math.h>

#include<stdio.h>

#include<string.h>

#include<vector>

#include<algorithm>
#include<utility>



typedef long long ll;

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

#define rep1(i, n) for(int i=1; i < (int)(n); i++)

#define all(x) (x).begin(),(x).end()

#define fill(x,y) memset(x,y,sizeof(x))

#define debug1(i) cout << i << '\n'

#define debug2(i,j) cout << i << j << '\n'



using namespace std;



int main() {
	int n, m;
	cin >> n >> m;
	if (m >= 0) {
		cout << (m+1 + n + m - 1) * (n-1) / 2;
	}
	else {
		if (m + n > 0)cout << (m + n + m - 1) * n / 2;
		else cout << (m + m + n - 2) * (n - 1) / 2;
	}
}


Measured memory_bytes: 256
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    dp = [math.inf]*(N+1)
    dp[0] = 0
    for i in range(N):
        if i+1 <= N:
            dp[i+1] = min(dp[i+1], dp[i]+1)
            six = 6
            while i+six <= N:
                dp[i+six] = min(dp[i+six], dp[i]+1)
                six *= 6
            nine = 9
            while i+nine <= N:
                dp[i+nine] = min(dp[i+nine], dp[i]+1)
                nine *= 9
    return dp[N]


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


Measured memory_bytes: 74868
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,ans=0;
int main(){
  cin>>n;
  for(ll i=1;i<=n;i++){
    ll j=n/i;
    ans+=j*(j+1)*i/2;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3576
object Main {
	val s = new java.util.Scanner(System.in)
	def main(args: Array[String]) {
		val a, b, c = s.nextInt()
		for (i <- 1 to b)
			if (a * i % b == c) {
				println("YES")
				return
			}
		println("NO")
	}
}


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

int main(){
    int N,k;
    1<=N<=100;
    cin>>N;
    int max;
    for(k=0;k<10;k++){
        max=std::pow(2,k);
        if(max>N){
            max=std::pow(2,k-1);
            break;
        }
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 1000000
#define INFTY (1<<21)

int n,A[MAX+1];

void maxHeapify(int i)
{
  int left,right,largest,a;
  left=2*i;
  right=2*i+1;
  if(left<=n && A[left]>A[i])
    largest=left;
  else
    largest=i;
  if(right<=n && A[right]>A[largest])
    largest=right;
  if(largest!=i)
    {
      a=A[i];
      A[i]=A[largest];
      A[largest]=a;
      maxHeapify(largest);
    }
}

int extract()
{
  int x;
  if(n<1)
    return -INFTY;
  x=A[1];
  A[1]=A[n--];
  maxHeapify(1);
  return x;
}

void increaseKey(int i,int key)
{
  int a;
  if(key<A[i])
    return;
  A[i]=key;
  while(i>1 && A[i/2] < A[i])
    {
      a=A[i];
      A[i]=A[i/2];
      A[i/2]=a;
      i/=2;
    }
}

void insert(int key)
{
  n++;
  A[n]=-INFTY;
  increaseKey(n,key);
}

int main()
{
  int k;
  char com[10];

  while(1)
    {
      scanf("%s",com);
      if(com[0]=='e' && com[1]=='n')
        break;
      if(com[0]=='i')
        {
          scanf("%d",&k);
          insert(k);
        }
      else
        {
          printf("%d\n",extract());
        }
    }
  return 0;
}


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

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n;
int a[N];

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    int k = n / 2;
    int m = a[k - 1];
    int m1 = a[k];
    if (m == m1) {
        cout << 0 << endl;
    } else {
        cout << m1 - m << endl;
    }

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  map<string,int> S;
  for (int i = 0; i < N; i++) {
    string c;
    cin >> c;
    if (!S.count(c)) {
      S[c] = i;
    }
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 19228
#include<stdio.h>

int main(){
	int n, m, i, j;
	int now_x, now_y;
	int r;
	char direc;
	int x[3][20];
	while(1){

		for(i=0; i<20; i++){
			for(j=0; j<3; j++)
				x[j][i] = 0;
		}
		n=0;
		m=0;
		now_x=10;
		now_y=10;
		scanf("%d", &n);
		if(n==0)
			return 0;
		for(i=0; i<n; i++)
			scanf("%d %d", &x[0][i], &x[1][i]);
		scanf("%d", &m);
		for(j=0; j<m; j++){
			scanf("%s %d", &direc, &r);
			switch (direc){
				case 'N':
					for(i=0; i<n; i++){
						if((now_x == x[0][i])&&(now_y <= x[1][i])&&(x[1][i] <= now_y+r))
							x[2][i]=1;
					}
					now_y += r;
					break;
				case 'E':
					for(i=0; i<n; i++){
						if((now_y == x[1][i])&&(now_x <= x[0][i])&&(x[0][i] <= now_x+r))
							x[2][i]=1;
					}
					now_x += r;
					break;
				case 'S':
					for(i=0; i<n; i++){
						if((now_x == x[0][i])&&(now_y-r <= x[1][i])&&(x[1][i] <= now_y))
							x[2][i]=1;
					}
					now_y -= r;
					break;
				case 'W':
					for(i=0; i<n; i++){
						if((now_y == x[1][i])&&(now_x-r <= x[0][i])&&(x[0][i] <= now_x))
							x[2][i]=1;
					}
					now_x -= r;
					break;
			}
		}
		for(i=0; i<n; i++){
			if(x[2][i] == 0){
				printf("No\n");
		         	break;
                        }

		}
		if(i == n)
			printf("Yes\n");
	}
}

Measured memory_bytes: 584
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

from bisect import bisect_left, bisect_right

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

A.sort()

fac = [1]
inv = [1]
for i in range(1, N + 1) :
  fac.append(fac[-1] * i % mod)
  inv.append(pow(fac[-1], mod - 2, mod))
  
def nCr(n, r) :
  if r < 0 or n < r :
    return 0
    
  return fac[n] * inv[n - r] * inv[r] % mod

ret = 0
for i in range(N) :
  l = N - i - 1
  u = i
  ret += A[i] * (nCr(u, K - 1) - nCr(l, K - 1))
  ret %= mod
  
print(ret)

Measured memory_bytes: 67880
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N;
    cin >> N;
    ll A[N];
    ll B[N];
    for(ll i = 0;i < N;i++) cin >> A[i];
    for(ll i = 0;i < N;i++)cin >> B[i];

    vector<ll> good;
    vector<ll> bad; 
    for(ll i = 0;i < N;i++) {
        if(A[i] - B[i] > 0) good.push_back(A[i] - B[i]);
        else if(A[i] - B[i] < 0) bad.push_back(B[i] - A[i]);
    }
    sort(good.begin(),good.end(),greater<ll>());
    sort(bad.begin(),bad.end());
    ll c_g = 0;
    ll c_b = 0;
    ll num = 0;
    ll s_g = good.size();
    ll s_b = bad.size();
    while(true){
        if(c_g == s_g && num < 0) break;
        if(c_b == s_b && num >= 0) break;
        if(num >= 0){
            num -= bad[c_b];
            c_b++;
        }
        else{
            num += good[c_g];
            c_g++;
        }
    }
    if(num >= 0) cout << c_g + c_b << "\n";
    else cout << -1 << "\n";
    
    return 0;
}

Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
	ll ans=0;
	rep(i,a,b+1){
		string s=to_string(i);
		string t=s;
		reverse(all(t));
		if(s==t) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#include<sstream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int a=0,b=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='A')
		{
			a++;
		}
		else if(s[i]=='B')
		{
			b++;
		}
	}
	
	if(a>=1&&b>=1)
	{
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
//Dlove's template
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define R register
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define sqr(_x) ((_x) * (_x))
#define Cmax(_a, _b) ((_a) < (_b) ? (_a) = (_b), 1 : 0)
#define Cmin(_a, _b) ((_a) > (_b) ? (_a) = (_b), 1 : 0)
#define Max(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define Min(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define Abs(_x) (_x < 0 ? (-(_x)) : (_x))

using namespace std;

namespace Dntcry
{
	inline int read()
	{
		R int a = 0, b = 1; R char c = getchar();
		for(; c < '0' || c > '9'; c = getchar()) (c == '-') ? b = -1 : 0;
		for(; c >= '0' && c <= '9'; c = getchar()) a = (a << 1) + (a << 3) + c - '0';
		return a * b;
	}
	inline ll lread()
	{
		R ll a = 0, b = 1; R char c = getchar();
		for(; c < '0' || c > '9'; c = getchar()) (c == '-') ? b = -1 : 0;
		for(; c >= '0' && c <= '9'; c = getchar()) a = (a << 1) + (a << 3) + c - '0';
		return a * b;
	}
	const int Maxn = 100010;
	struct node
	{
		int yer, id;
		bool operator < (const node &b) const
		{
			return yer < b.yer;
		}
	}S[Maxn];
	struct name
	{
		int x, y;
	}P[Maxn];
	vector<node>v[Maxn];
	int n, m, top;
	int Main()
	{
		n = read(), m = read();
		for(R int i = 1, p, y; i <= m; i++)
		{
			p = read(), y = read();
			v[p].push_back((node){y, i});
		}
		for(R int i = 1; i <= n; i++)
		{
			top = 0;
			for(R int j = 0; j < v[i].size(); j++)
				S[++top] = v[i][j];
			sort(S + 1, S + top + 1);
			for(R int j = 1; j <= top; j++)
				P[ S[j].id ] = (name){i, j};
		}
		for(R int i = 1; i <= m; i++)
			printf("%06d%06d\n", P[i].x, P[i].y);
		return 0;
	}
}
int main()
{
	return Dntcry :: Main();
}


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


int marks[100];

int main() {
    string str;
    cin >> str;
    
    string res = "";
    for (int i = 0; i < (int) str.size(); ++i) {
        if ( isdigit(str[i]) ) res += str[i];
        else if (str[i] == 'B') {
            if (res.size() == 0) continue;
            res.pop_back();
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;
const ll num[4] = {-1, 0, 1, 0};

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> vec(n);
    vector<ll> so(n);

    rep(i, 0, n)
    {
        cin >> vec[i];
        so[i] = vec[i];
    }
    sort(all(so));
    rep(i, 0, n)
    {
        if (vec[i] < so[n / 2])
            cout << so[n / 2] << endl;
        else
            cout << so[n / 2 - 1] << endl;
    }
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int x,a;
	cin >> x >> a;
	if(x < a) cout << 0 << endl;
	else cout << 10 << endl;
	return 0;
}


Measured memory_bytes: 256
from math import radians, cos, sin, sqrt

a, b, c = map(float, input().split())

c = radians(c)
h = b * sin(c)
s = a * h * 1 / 2

d = sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(c))
l = a + b + d

print(s)
print(l)
print(h)


Measured memory_bytes: 5688
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 2e5 + 7;
struct UF {
	int fa[N];
	void ini() { rep(i, 0, N) fa[i] = i; }
	int getf(int d) { return fa[d] == d ? d : fa[d] = getf(fa[d]); }
	void comb(int a, int b) { 
		if ((a = getf(a)) == (b = getf(b))) return;
		fa[a] = b;
	}
}	uf1, uf2;
int n, m1, m2;
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n >> m1 >> m2;
	uf1.ini();
	uf2.ini();
	rep(i, 0, m1) {
		int a, b; cin >> a >> b, a--, b--;
		uf1.comb(a, b);
	}
	rep(i, 0, m2) {
		int a, b; cin >> a >> b, a--, b--;
		uf2.comb(a, b);
	}
	map<pii, int> Map;
	rep(i, 0, n) Map[{uf1.getf(i), uf2.getf(i)}]++;
	rep(i, 0, n) cout << Map[{uf1.getf(i), uf2.getf(i)}] << " \n"[i == n - 1];
	
	return 0;
}

Measured memory_bytes: 13696
s = input().rstrip()
d = ['dream', 'dreamer']
e = ['erase', 'eraser']
ch = d + e

st = [s]

def search_(s, st, ch):
    if len(s) == 0:
        return
    if len(s) < len(ch):
        return
    else:
        if s[:len(ch)] == ch:
            st.append(s[len(ch):])

def search(s):
    if len(s) == 0:
        return True
    if s[0] == 'd' or s[0] == 'e':
        for ci in ch:
            if search_(s, ci):
                return True
    return False

while st:
    s = st.pop(0)
    if len(s) == 0:
        print('YES')
        exit()
    if s[0] == 'd' or s[0] == 'e':
        for ci in ch:
            search_(s, st, ci)
print('NO')


Measured memory_bytes: 3472
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int n, m;
vector<int> g[100005];
vector<int> vi(100005), v;

void dfs(int s) {
	if (vi[s]) return;
	vi[s] = true;
	for (int c : g[s]) dfs(c);
	v.emplace_back(s);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].emplace_back(b);
	}
	rep(i, n) dfs(i);
	vector<int> dp(n, 0);
	int ans = 0;
	for (int c : v) {
		for (int p : g[c]) {
			maxs(dp[c], dp[p] + 1);
		}
		maxs(ans, dp[c]);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){

	string s;
	string t;

	cin >> s >> t;


	vector<vector<int>> DP(s.size(),vector<int>(t.size(),0));

	DP[0][0] = s[0]==t[0];

	for(int j=1;j<t.size();j++){

		if(s[0]==t[j]){
			DP[0][j] = 1;
		}else{
			DP[0][j] = DP[0][j-1];
		}

	}

	//init
	for(int i=1;i<s.size();i++){
		if(t[0]==s[i]){
			DP[i][0] = 1;
		}else{
			DP[i][0] = DP[i-1][0];
		}
	}

	//bottom up approach
	for(int i=1;i<s.size();i++){
		for(int j=1;j<t.size();j++){

			if(s[i]==t[j]){
				DP[i][j] = max(DP[i-1][j-1]+1,max(DP[i-1][j],DP[i][j-1]));
			}else{
				DP[i][j] = max(DP[i-1][j],DP[i][j-1]);
			}

		}
	}

	//extract the string from DP
	
	string ans;

	int i=s.size()-1;
	int j=t.size()-1;


	while((i>0)&&(j>0)){

			if(DP[i][j]==DP[i][j-1]){
				j--;
			}else if(DP[i][j]==DP[i-1][j]){
				i--;
			}else{
				ans = s[i]+ ans;
				i--;
				j--;
			}

	}

	if((i==0)&&(DP[0][j]==1)){
		
		while((j>=0)&&(DP[0][j]==1)){
			j--;
		}
			ans = t[j+1] + ans;
	}


	if((j==0)&&(DP[i][0]==1)){

		while((i>=0)&&(DP[i][0]==1)){
			i--;
		}
			ans = s[i+1] + ans;
	}


	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 38960
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int b=0,x=1,n,a;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(x==a)
            x++;
        else
            b++;
    }
    if(x==1 && b!=0)
        cout<<"-1";
    else
        cout<<b;
}


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

template <typename Monoid>
class SegmentTree {
	using T = typename Monoid::type;
	const int n;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
public:
	SegmentTree(int n_) :
		n(size(n_)), data(n * 2, Monoid::id()) {}
	void init(const vector<T>& data_) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
	}
	void update(int p, T val) {
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = Monoid::op(data[p * 2], data[p * 2 + 1]);
	}
	void add(int p, T val) {
		p += n;
		data[p] += val;
		while (p >>= 1) data[p] = Monoid::op(data[p * 2], data[p * 2 + 1]);
	}
	T find(int i) {
		return data[i + n];
	}
	T find(int l, int r) {
		l += n; r += n + 1;
		T res1 = Monoid::id(), res2 = Monoid::id();
		while (l < r) {
			if (l & 1) res1 = Monoid::op(res1, data[l++]);
			if (r & 1) res2 = Monoid::op(data[--r], res2);
			l >>= 1; r >>= 1;
		}
		return Monoid::op(res1, res2);
	}
};

struct RMQ {
	using type = int;
	static const type id() { return INT_MAX; }
	static type op(const type& l, const type & r) { return min(l, r); }
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, com, x, y;
	cin >> n >> q;
	SegmentTree<RMQ> st(n);
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", st.find(x, y));
		}
		else {
			st.update(x, y);
		}
	}
	return 0;
}

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

int main() {
	int x;
	int y;
	while(1){
		cin>>x>>y;
		if(x==0&&y==0){
			break;
		}
		else if(x<y){
			cout<<x<<" "<<y<<"\n";
		}
		else{
			cout<<y<<" "<<x<<"\n";
		}
	}
}


Measured memory_bytes: 1160
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <unordered_set>
using namespace std;

#define P 1000000007
int n, a[110000], b[110000], hi[110000], lo[110000];
int ans;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	for (int i = 1; i <= n; i++)
		lo[i] = 1, hi[i] = 1000000000;
	for (int i = 1; i <= n; i++)
		if (a[i] != a[i - 1])
			hi[i] = min(hi[i], a[i]),
			lo[i] = max(lo[i], a[i]);
		else
			hi[i] = min(hi[i], a[i]);
	for (int i = 1; i <= n; i++)
		if (b[i] != b[i + 1])
			hi[i] = min(hi[i], b[i]),
			lo[i] = max(lo[i], b[i]);
		else
			hi[i] = min(hi[i], b[i]);
	ans = 1;
	for (int i = 1; i <= n; i++) {
		if (lo[i] > hi[i])
			ans = 0;
		else
			ans = 1LL * ans * (hi[i] - lo[i] + 1) % P;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] arr = s.split("[^ACGT]");
		
		int maxLen = 0;
		for (String str : arr)
			maxLen = Math.max(maxLen, str.length());
		
		System.out.println(maxLen);
		
		sc.close();
	}
	
}




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

const int maxn = 2e5+5;
int n;
vector<int> adj[maxn];

int color[maxn];
int c[2];
void dfs(int i) {
    ++c[color[i]];
    for (int j: adj[i]) {
        if (color[j] != -1) continue;
        color[j] = 1^color[i];
        dfs(j);
    }
}
vector<int> v[3];
int ans[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    memset(color,-1,sizeof color);
    color[1] = 0;
    dfs(1);
    int x = n/3;
    for (int i = 1; i <= n; i++) {
        v[i%3].push_back(i);
    }
    if (c[0] <= x) {
        for (int i = 1; i <= n; i++) {
            if (color[i] == 0) {
                ans[i] = v[0].back();
                v[0].pop_back();
            }
            else {
                if (!v[1].empty()) {
                    ans[i] = v[1].back();
                    v[1].pop_back();
                }
                else if (!v[2].empty()) {
                    ans[i] = v[2].back();
                    v[2].pop_back();
                }
                else {
                    ans[i] = v[0].back();
                    v[0].pop_back();
                }
            }
        }
    }
    else if (c[1] <= x) {
        for (int i = 1; i <= n; i++) {
            if (color[i] == 1) {
                ans[i] = v[0].back();
                v[0].pop_back();
            }
            else {
                if (!v[1].empty()) {
                    ans[i] = v[1].back();
                    v[1].pop_back();
                }
                else if (!v[2].empty()) {
                    ans[i] = v[2].back();
                    v[2].pop_back();
                }
                else {
                    ans[i] = v[0].back();
                    v[0].pop_back();
                }
            }
        }
    }
    else {
        for (int i = 1; i <= n; i++) {
            if (color[i] == 1) {
                if (!v[1].empty()) {
                    ans[i] = v[1].back();
                    v[1].pop_back();
                }
                else {
                    ans[i] = v[0].back();
                    v[0].pop_back();
                }
            }
            else {
                if (!v[2].empty()) {
                    ans[i] = v[2].back();
                    v[2].pop_back();
                }
                else {
                    ans[i] = v[0].back();
                    v[0].pop_back();
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
}


Measured memory_bytes: 17656
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		Orique oq = new Orique();
		for (int i = 0; i < n; i++) {
			oq.inque(sc.next(), sc.nextInt());
		}
		sc.close();
		oq.RoundRobinScheduling(q);
	}
}

class Orique {
	private class kakunou {
		String kstr;
		int kint;
		int kprenum;

		void setkakunou(String s, int i, int pre) {
			kstr = s;
			kint = i;
			kprenum = pre;
		}
	}

	private int length = 0;
	ArrayList<String> str = new ArrayList<String>();
	ArrayList<Integer> in = new ArrayList<Integer>();
	kakunou k;
	private ArrayList<Integer> prenumber = new ArrayList<Integer>();

	Orique() {
		k = new kakunou();
	}

	public void inque(String t, int i) {
		str.add(t);
		in.add(i);
		prenumber.add(i);
		length++;
	}

	private void inque(kakunou k) {
		str.add(k.kstr);
		in.add(k.kint);
		prenumber.add(k.kprenum);
		length++;
	}

	private void deque() {
		k.setkakunou(str.get(0), in.get(0), prenumber.get(0));
		str.remove(0);
		in.remove(0);
		prenumber.remove(0);
		length--;

	}
    public void RoundRobinScheduling(int q) {
		
		int total=0;
		deque();
		while(true){
			int t1=k.kint-q;
			if(t1>0){
				total=total+q;
				k.kint=t1;
				inque(k);
				
			}else{
				total=total+k.kint;
				System.out.println(k.kstr+" "+total);
				}
			if(length>0)deque();
			else break;
		}
		}}

Measured memory_bytes: 65552
H, W = map(int, input().split())
S = [["."] * (W + 2)] + [["."] + list(input()) + ["."] for _ in range(H)] + [["."] * (W + 2)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if S[h][w] == "#":
            continue
        count = 0
        for dh in range(-1, 2):
            for dw in range(-1, 2):
                if S[h + dh][w + dw] == "#":
                    count += 1
        S[h][w] = str(count)
    print("".join(S[h][1:W+1]))


Measured memory_bytes: 3188
import math
def combinations(n, r):
  if n == r:
    return 1
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
s = [sorted(input())]
ans = 0
for i in range(N-1):
  s_i = sorted(input())
  s.append(s_i)
s = sorted(s)
count=1
for j in range(N-1):
  if s[j] == s[j+1]:
    count+=1
  else:
    if count != 1:
      ans += combinations(count,2)
    count=1
if count != 1:
  ans += combinations(count,2)
print(ans)

Measured memory_bytes: 25472
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
static void Main(string[] args){
  var N = int.Parse(Console.ReadLine());
  var hash = new HashSet<int> ();
  for(int i=0;i<N;i++){
  hash.Add(int.Parse(Console.ReadLine()));
  }
  Console.WriteLine(hash.Count());
}
}


Measured memory_bytes: 13280
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	cout << 0 << endl;
	string s; cin >> s;
	if (s == "Vacant") return 0;
	bool evenIsMale = s == "Male";
	int low = 0, high = N;
	for (;;)
	{
		int mid = (low + high) / 2;
		cout << mid << endl;
		cin >> s; if (s == "Vacant") break;
		if (mid % 2 == 0)
		{
			if (evenIsMale && s == "Male")
			{
				low = mid;
			}
			else if (!evenIsMale && s == "Female")
			{
				low = mid;
			}
			else
			{
				high = mid;
			}
		}
		else
		{
			if (evenIsMale && s == "Female")
			{
				low = mid;
			}
			else if (!evenIsMale && s == "Male")
			{
				low = mid;
			}
			else
			{
				high = mid;
			}
		}
	}
}


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

class Program
{
    static void Main(string[] args)
    {
        int[] nm = Console.ReadLine()
            .Split(' ')
            .Select(int.Parse)
            .ToArray();
        int n = nm[0];
        int m = nm[1];

        string[] a = new string[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = Console.ReadLine();
        }

        string[] b = new string[m];
        for (int i = 0; i < m; i++)
        {
            b[i] = Console.ReadLine();
        }

        int count = 0;
        for (int w = 0; w <= n - m; w++)
        {
            for (int h = 0; h <= n - m; h++)
            {
                // check
                for (int i = 0; i < m; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (b[i][j] == a[w + i][h + j])
                        {
                            count++;
                        }
                    }
                }
                if (count == m * m)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                count = 0;
            }
        }

        Console.WriteLine("No");
    }
}


Measured memory_bytes: 11348
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import deque

h, w = na()
maze = nsn(h)

def bfs(sx, sy):
    q = deque()
    q.append((sx, sy))
    dist = [[inf] * w for _ in range(h)]
    dist[sy][sx] = 0
    dx, dy = [1, 0, 0, -1], [0, 1, -1, 0]
    res = 0
    while len(q):
        p = q.popleft()
        cx, cy = p
        for i in range(4):
            nx, ny = cx + dx[i], cy + dy[i]
            if nx < 0 or nx >= w:
                continue
            if ny < 0 or ny >= h:
                continue
            if dist[ny][nx] != inf:
                continue
            if maze[ny][nx] == '#':
                continue
            update = dist[cy][cx] + 1
            dist[ny][nx] = update
            res = max(res, update)
            q.append((nx, ny))
    
    return res

def main():
    ans = 0

    for y in range(h):
        for x in range(w):
            if maze[y][x] == '#':
                continue
            ans = max(ans, bfs(x, y))

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
N = int(input())
dp = [[0]*3 for i in range(100100)]

for i in range(N):
    a,b,c = map(int, input().split())
    # print(a,b,c)
    dp[i+1][0] = max(dp[i][1],dp[i][2]) + a
    dp[i+1][1] = max(dp[i][2],dp[i][0]) + b
    dp[i+1][2] = max(dp[i][0],dp[i][1]) + c

print(max(dp[N]))

Measured memory_bytes: 22772
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector
#include <boost/multiprecision/integer.hpp>

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

int N; cin >> N;
VI T(N), A(N); invec(T), invec(A);

i64 cnt = 1;
i64 Tmax = *max_element(ALL(T));
i64 Amax = *max_element(ALL(A));
if (Tmax != Amax){
    cout << "0\n";
    return 0;
}
int i = 1, j = N - 2;
for(; i < N && T[i] < Tmax; ++i){
    if (T[i-1] == T[i]) (cnt *= T[i]) %= MOD;
}
for(; j >= 0 && A[j] < Amax; --j){
    if (A[j] == A[j + 1]) (cnt *= A[j]) %= MOD;
}
if (N > 1 && j < i){
    cout << "0\n";
    return 0;
}
if (T[0] == Tmax) i = 0;
if (A[N-1] == Amax) j = N-1;
cout << cnt * boost::multiprecision::powm(Tmax, max(0, j-i - 1), MOD) % MOD << "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



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


using namespace std;

int main()
{
    int w,a,b;

    cin >> w >> a >> b;

    if(b > a)
    {
        if(w+a > b )
            cout << "0";
        
        else
        {
            cout << b - w - a;
        }
        
    } 

    else
    {
        if(w + b > a )
            cout << "0";
        
        else
        {
            cout << a - w - b;
        }
    }
      
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N;
    long long A, B;
    long long a_max = 0, b_low = 1000000000;
    cin >> N;
    REP(i, N){
        cin >> A >> B;
        a_max = max(a_max, A);
        b_low = min(b_low, B);
    }
    cout << a_max + b_low;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

MOD = 998244353

def init(G, robots, fs, p):
    q = p
    while q < len(robots) and robots[q][0] < robots[p][0] + robots[p][1]:
        if fs[q]:
            G[p].append(q)
            fs[q] = False
            q = init(G, robots, fs, q) - 1
        q += 1
    return q

def calc(G, p, fs):
    fs[p] = False
    if len(G[p]) == 0:
        return 2
    tmp = 1
    for v in G[p]:
        tmp *= calc(G, v, fs)
        tmp %= MOD
    tmp += 1
    return tmp

def main():
    n = int(input())
    robots = [list(map(int, input().split())) for _ in range(n)]
    G = [[] for _ in range(n)]
    robots.sort(key=lambda x: x[0])
    fs = [True]*n
    q = 0
    while q < n:
        if fs[q]:
            fs[q] = False
            init(G, robots, fs, q)
        else:
            q += 1
    fs = [True]*n
    ans = 1
    for i in range(n):
        if fs[i]:
            ans *= calc(G, i, fs)
            ans %= MOD
    print(ans % MOD)

if __name__ == "__main__":
    main()

Measured memory_bytes: 619644
import java.util.*;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int[] b = new int[q];
        for (int i = 0; i < q; i++) {
            b[i] = sc.nextInt();
        }
        boolean[] c = new boolean[40001];
        c[0] = true;
        for (int i = 0; i < 1<<n; i++) {
            int t = 0;
            for (int j = 0; j < n; j++) {
                if((i>>j & 1) != 1)continue;
                t += a[j];
            }
            c[t] = true;
        }
        for (int i = 0; i < q; i++) {
            System.out.println(c[b[i]] ? "yes" : "no");
        }
        sc.close();

    }

}



Measured memory_bytes: 26904
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 1000000007

func main() {
	stdin.Split(bufio.ScanWords)
	X := getStdin()
	Y := getStdin()
	value := 0

	if(X==1){
		value+=300000
	}
	if(X==2){
		value+=200000
	}
	if(X==3){
		value+=100000
	}
	if(Y==1){
		value+=300000
	}
	if(Y==2){
		value+=200000
	}
	if(Y==3){
		value+=100000
	}
	if(X==1 && Y==1){
		value+=400000
	}
	fmt.Println(value)
	
}

var stdin = bufio.NewScanner(os.Stdin)

func getStdin() int {
	stdin.Scan()
	if err := stdin.Err(); err != nil {
		fmt.Fprintln(os.Stderr, err)
	}
	line, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	return line
}

func getStd() string {
	stdin.Scan()
	if err := stdin.Err(); err != nil {
		fmt.Fprintln(os.Stderr, err)
	}
	line := stdin.Text()
	return line
}

//Combination:b+cCc
func factorial(b int, c int) int {
	var sum, csum, bsum = 1, 1, 1
	for j := 0; j < c; j++ {
		csum = (csum * (c - j)) % mod
		bsum = (bsum * (b + c - j)) % mod
	}
	sum = div(bsum, csum)
	return sum
}

func mul(a int, b int) int {
	return ((a % mod) * (b % mod)) % mod
}

func div(a int, b int) int {
	return mul(a, power(b, mod-2))
}

func power(x int, y int) int {
	if y == 0 {
		return 1
	}
	if y == 1 {
		return x % mod
	}
	a := power(x, y/2) % mod
	if y%2 == 0 {
		b := a * a % mod
		return b
	}
	b := ((a * a) % mod) * x % mod
	return b
}


Measured memory_bytes: 640