akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

//ABC047-A-キャンディーと2人の子供
//http://abc047.contest.atcoder.jp/tasks/abc047_a
class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("10 30 20");
            //Yes
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("30 30 100");
            //No
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("56 25 31");
            //Yes
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();

        Array.Sort(wkArr);

        if (wkArr[2] == wkArr[1] + wkArr[0]) 
            Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}


Measured memory_bytes: 3032
#include<stdio.h>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <queue>
#include<iomanip>
#include<bitset>
#include<stack>
#include<set>
#include<limits>
#include <complex>
#include<cstdlib>
using namespace std;

vector<vector<int>>outs;
int N, M, K;
bool check(const vector<int>&nums) {
	for (int i = 0; i < N-1; ++i) {
		if (outs[nums[i]][nums[i + 1]]) {
			return false;
		}
	}
	if (outs[nums[N - 1]][nums[0]]) {
		return false;
	}
	else {
		return true;
	}
}

int main() {
	while (1) {

		int N, M, P; cin >> N >> M >> P;
		if (!N)break;
		int bo;
		int si = 0;
		for (int i = 0; i < N; ++i) {
			int a; cin >> a;
			if (i == M - 1) {
				bo = a;
			}
			si += a;
		}
		if (bo) {
			int ans = ((100 - P)*si) / bo;
			cout << ans << endl;
		}
		else {
			cout << 0 << endl;
		}
	
	}
	
	return 0;
}

Measured memory_bytes: 3080
#include <stdio.h>

void mergeSort(int *, int, int);
void merge(int *, int, int, int);

long long count = 0;

int main(){
  int S[200000], n, i, j, temp;

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

  mergeSort(S, 0, n);

  printf("%lld\n", count);
  
  return 0;
}

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

void merge(int *A, int left, int mid, int right){
  int n1, n2, L[100001], R[100001], i, j, k;

  n1 = mid - left;
  n2 = right - mid;

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

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

Measured memory_bytes: 2156
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
inline void read(int &x)
{
	x=0;
	int p=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
int n;
int f[110][6][3];
int p[110][15];
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=5;j++)
			for(int k=1;k<=2;k++)read(f[i][j][k]);
	}
	int ans=-0x7f7f7f7f;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=10;j++)read(p[i][j]);
	int maxn=(1<<10)-1;
	for(int i=1;i<=maxn;i++)
	{
		int anss=0;
		for(int j=1;j<=n;j++)
		{
			int tot=0;
			for(int k=1;k<=10;k++)
				if(f[j][(k+1)/2][(k-1)%2+1]&&(i&(1<<(k-1))))tot++;
			anss+=p[j][tot];
		}
		ans=max(ans,anss);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define INF 2147483647
#define fi first
#define se second
int abs(int a,int b){ 
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
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;
}
int zero[100000000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,c=0;
  int b[100000];
  cin>>a;
  for(int i=0;i<a*2;i++) cin>>b[i];
  sort(b,b+(a*2),greater<int>());
  for(int i=0;i<a*2;){
      //  cout<<b[i]<<" "<<b[i+1]<<"\n";
      c=min(b[i],b[i+1])+c;i+=2;
      
  }
  cout<<c<<"\n";
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MOD = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 300100;

ll T,N,a,b,c,d,e,f,K,t,M;

ll dp[10][10];

ll ask(int l, int e){
  if(l==0){
    if (e==10)return 0;
    return 1;
  }
  int ans = 0;
  if (e==10){
    for (int i=1;i<=10;++i)ans += ask(l-1,i);
  }else{
    for(int i=0;i<10;++i){
      if(abs(e-i) <= 1){
        ans += ask(l-1, i);
      }
    }
  }
  return dp[l][e] = ans;
}

int main(){
    cin>>N;
    --N;
    vi out;
    int leadingzero = 1;
    for (int l=10;l>=0;--l){
      for (int pp = 0;pp<10;++pp){
        if (!leadingzero && SZ(out) && abs(out.back() - pp) > 1)continue;
        ll t = ask(l, pp);
        if (leadingzero && pp==0)t = ask(l,10);

        // cout<<"Ask "<<l<<' '<<pp<<' '<<t<<'\n';
        if (t <= N){
          N -= t;
          continue;
        }else{
          out.pb(pp);
          if (pp != 0)leadingzero = 0;
          break;
        }
      }
    }
    reverse(ALL(out));
    while (SZ(out)){
      if (out.back() == 0)out.pop_back();
      else break;
    }
    reverse(ALL(out));
    for (auto i : out)cout<<i;cout<<'\n';
  
}

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

int main()
{
  int i, n, q, *queue, head, tail, execution, time;
  char (*name)[10];

  head = 0;
  tail = 0;
  time = 0;

  scanf("%d%d", &n, &q);

  queue = (int *)malloc( (n+1) * sizeof(int));
  name = (char (*)[10])malloc( (n+1) * 10 * sizeof(char));

  for( i=0; i<n; i++ )
    {
      scanf("%s%d", name[i], &queue[i]);
      tail++;
    }

  while(1)
    {

      if( tail == head ) break;

      execution = queue[head];

      if( execution - q > 0 )
	{
	  queue[tail] = execution - q;
	  strcpy(name[tail], name[head]);
	  time += q;
	  tail = ( tail + 1 ) % ( n + 1 );
	}

      else if( execution - q <= 0 )
	{
	  time += execution;
	  printf("%s %d\n", name[head], time);
	}

      head = (head+1) % (n+1);
    }

  free( queue );
  free( name );

  return 0;
}



Measured memory_bytes: 2108
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let m: i64 = read();
    let n: usize = read();
    let a: Vec<i64> = read_n(n);
    let mut ans = -1;
    if a.iter().sum::<i64>() <= m {
        ans = m - a.iter().sum::<i64>();
    }
    println!("{}", ans);
}


Measured memory_bytes: 2792
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

int main(void) {
	string s;

	cin >> s;

	s[0] = '2';
	s[1] = '0';
	s[2] = '1';
	s[3] = '8';

	cout << s << endl;
 
	return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = [0] * N

for x in range(1, int(N**0.5)+1):
    for y in range(1, int(N**0.5)+1):
        for z in range(1, int(N**0.5)+1):
            n = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if n <= N:
                ans[n-1] += 1

for n in range(N):
    print(ans[n])


Measured memory_bytes: 9368
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

char s[100010]={};
int main(void){
	scanf("%s",s);
	int ls=strlen(s);
	rep(i,ls){
		if(s[i]==s[i+1]){
			printf("%d %d\n",i+1,i+2);
			return 0;
		}
		else if(s[i]==s[i+2]){
			printf("%d %d\n",i+1,i+3);
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
}






Measured memory_bytes: 384
function zero_padding_number(num){
  return ('000000' + num.toString()).slice(-6);
}

function main(input){
  const lines = input.split('\n');
  const N =parseInt(lines[0].split(' ')[0]);
  const M =parseInt(lines[0].split(' ')[1]);
  var pys = [];
  for(var i=0;i<M;i++){
    var line = lines[1+i].split(' ').map(x => parseInt(x))
    pys.push([i, line[0],line[1]]);
  }

  var p_y_sorted = pys.sort(function(a,b){
    if(a[1]==b[1]){return a[2]-b[2];}
    return a[1]-b[1];
  })


  var current_p=0;
  var current_city_index=1;
  for(var i=0;i<p_y_sorted.length;i++){
    var current_city = p_y_sorted[i];
    if(current_p!=current_city[1]){
      current_p=current_city[1]
      current_city_index=1;
    }
    var id = zero_padding_number(current_city[1])+zero_padding_number(current_city_index);
    p_y_sorted[i].push(id);
    current_city_index++;
  }

  const stdin_sorted_cities = p_y_sorted.sort(function(a,b){return a[0]-b[0];})
  for(var i=0;i<M;i++){
    console.log(stdin_sorted_cities[i][3])
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 80100
#include <iostream>
using namespace std;
int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  A *= 100;
  B *= 100;
  int water;
  int suger, max_suger{0};
  int all, max_all{0};
  double dens, max_dens{-1.0};
  double limit_dens{E / (100.0 + E)};
  for (int a{0}; a <= F; a += A) {
    for (int b{0}; a + b <= F; b += B) {
      water = a + b;
      for (int c{((F - water) / C) * C}; c >= 0; c -= C) {
        for (int d{((F - (water + c)) / D) * D}; d >= 0; d -= D) {
          suger = c + d;
          all = water + suger;
          dens = suger * 1.0 / all;
          if (dens > limit_dens) continue;
          if (max_dens < dens) {
            max_all = all;
            max_suger = suger;
            max_dens = dens;
            break;
          }
        }
      }
    }
  }

  cout << max_all << " " << max_suger << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;	
ll dp[301][301];
int main()
{
	sync;
	ll n,m,l;
	cin>>n>>m>>l;

	for(ll i=0;i<=n;i++)
	for(ll j=0;j<=n;j++)
	dp[i][j]=1e17;
	
	for(ll i=0;i<m;i++)
	{
		ll x,y,v;
		cin>>x>>y>>v;
		dp[x][y]=dp[y][x]=v;
	}	

	for(ll i=1;i<=n;i++)
		for(ll j=1;j<=n;j++)
			for(ll k=1;k<=n;k++)
				dp[j][k]=min(dp[j][k],dp[j][i]+dp[i][k]);
	
	for(ll i=1;i<=n;i++)
		for(ll j=1;j<=n;j++)
			dp[i][j]=dp[i][j]<=l?1:1e17;
	
	for(ll i=1;i<=n;i++)
		for(ll j=1;j<=n;j++)
			for(ll k=1;k<=n;k++)
				dp[j][k]=min(dp[j][k],dp[j][i]+dp[i][k]);									

	ll q;cin>>q;
	while(q--)
	{
		ll s,t;
		cin>>s>>t;
		if(dp[s][t]==1e17)
		cout<<-1<<"\n";
		else
		cout<<dp[s][t]-1<<"\n";
	}
}

Measured memory_bytes: 1280
object Main extends App {
  val s = new java.util.Scanner(System.in)
  def f = { val n = s.nextInt; Iterator.continually(s.next).take(n) }
  val a = f.foldLeft(Map.empty[String, Int].withDefaultValue(0))((l, r) => l.updated(r, 1 + l(r)))
  val b = f.foldLeft(a)((l, r) => l.updated(r, l(r) - 1))
  println(Math.max(0, b.values.max))
}

Measured memory_bytes: 25424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    //ios::sync_with_stdio(false);
    //freopen("data.txt", "r", stdin);

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(a*b>=c*d?a*b:c*d)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
ll inf=1e10;

int main(){
  ll X,Y;
  cin>>X>>Y;
  ll cnt(1);
  while (true){
    if (X > Y) break;
    cnt += 1;
    X*=2;
  }
  cout << cnt -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct List {
    int p, n;
};

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

    int n;
    cin >> n;

    vector<List> vl(n + 2);
    List *l = &vl[1];
    vector<int> q(n);
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        p--;

        l[i] = { i - 1, i + 1 };
        q[p] = i;
    }
    l[-1] = { -1, 0 };
    l[n] = { n - 1, n };

    ll r = 0;
    for (int j = 0; j < n; j++) {
        int i = q[j];

        int x[4];
        x[1] = l[i].p;
        x[0] = l[x[1]].p;
        x[2] = l[i].n;
        x[3] = l[x[2]].n;

        r += (ll)j * (x[1] - x[0]) * (x[2] - i);
        r += (ll)j * (x[3] - x[2]) * (i - x[1]);

        l[x[1]].n = x[2];
        l[x[2]].p = x[1];
    }

    r += (ll)n * (n - 1) / 2;
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<tuple>
using namespace std;
int main() {
  string s;
  cin >> s;
  int N = s.size();
  for (int i=0; i<N; i++) {
    if (s[i]==',') s[i] = ' ';
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

int main() {

    int n;
    cin >>n;

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

    int m;
    cin >> m;

    vector<string> t(m);
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }

    map<string, int> ST;
    for (int i = 0; i < n; i++) {

        if ( ST.find(s[i]) == ST.end() ) {
            ST[s[i]] = 1;
        } else {
            ST[s[i]]++;
        }   
    }

    for (int i = 0; i < m; i++) {

        if ( ST.find(t[i]) == ST.end() ) {
            ST[t[i]] = -1;
        } else {
            ST[t[i]]--;
        }   
    }

    int ans = 0;

    for (auto p : ST) {
        ans = max(p.second, ans);
    }

    cout << ans << endl;
    
    return 0;

}


Measured memory_bytes: 256
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w, m = map(int, read().split())
    target = set()
    row = [0] * h
    col = [0] * w
    for _ in range(m):
        hi, wi = [int(i) - 1 for i in input().split()]
        target.add((hi, wi))
        row[hi] += 1
        col[wi] += 1
    row_max = max(row)
    r = [i for i in range(h) if row[i] == row_max]
    col_max = max(col)
    c = [i for i in range(w) if col[i] == col_max]
    for ri in r:
        for ci in c:
            if (ri, ci) not in target:
                print(row_max + col_max)
                return
    print(row_max + col_max - 1)


if __name__ == '__main__':
    main()


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

int main(){
	int N, T, l, r, ma = 0, sum = 0, temp[100100] = {};
	
	cin>>N>>T;
	
	for(int i = 0; i < N; i++){
		cin>>l>>r;
		temp[l]++;
		temp[r]--;
	}
	
	for(int i = 0; i <= T; i++){
		sum += temp[i];
		ma = max(sum, ma);
	}
	
	
	cout<<ma<<endl;
	
	return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 3001;
const ll inf = 1e18;
const ll mod = 1e9+7;
const int INF = 1 << 30;
const double eps = (1e-10);

void dg(ll ok){ cout << ok << endl; }

int dp[N][N];
string s, t;
int solve(int i, int j) {
    if (i == s.size() || j == t.size()) 
        return 0;
    int &ret = dp[i][j];
    if (ret != -1) return ret;
    ret = 0;
    if (s[i] == t[j]) {
        ret = solve(i + 1, j + 1) + 1;
    } else {
        ret = max(solve(i + 1, j), solve(i, j + 1));
    }
    return ret;
}

void trace(int i, int j) {
    if (i == s.size() || j == t.size()) 
        return ;
    if (s[i] == t[j]) {
        cout << s[i];
        trace(i + 1, j + 1);
        return;
    } else {
        if (solve(i, j) == solve(i + 1, j)) {
            return trace(i + 1, j);
        } else {
            return trace(i, j + 1);
        }
    }
    
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
    memset(dp, -1, sizeof(dp));
    cin >> s >> t;
    solve(0,0);
    trace(0,0);
    return 0;
}

Measured memory_bytes: 39096
s = gets.chomp
size = s.size
def kaibun(st)
  long = st.size
  x = true
  0.upto(long/2){|i| x = false if st[i] != st[long-1-i]}
  return x
end
t = s[0..((size/2)-1)]
u = s[((size/2)+1)..(size-1)]
if kaibun(s) == true && kaibun(t) == true && kaibun(u) == true
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  map<int, int> dict; // 各数字の登場回数
  for (int i=0; i<N; i++) {
    if (dict.count(a[i])) dict[a[i]]++;
    else dict[a[i]] = 1;
  }
  // dict[a[i]] = a[i]でないようなものは取り除く
  int res = 0;
  for (auto p: dict) {
    auto key = p.first;
    auto value = p.second;
    // dict[a[i]]>a[i]なら，登場回数がa[i]回になるまで取り除く
    if (key<value) res += value-key;
    // dict[a[i]]<a[i]なら，全て取り除く
    else if (key>value) res += value; 
  }
  cout << res << endl;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
bool c[53][53]={0};
LL l[53][53];
LL len,sum,sumb=0,h,w;
char m;
queue<pair<LL,LL>>q;
int main(){
	LL i,j,k;
	LL x[]={1,-1,0,0},y[]={0,0,1,-1};
	cin>>h>>w;
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			cin>>m;
			if(m=='.')c[i][j]=1;
			else sumb++;
		}
	}
	for(i=0;i<53;i++){
		for(j=0;j<53;j++)l[i][j]=(LL)1e9;
	}
	l[1][1]=0;
	q.push(make_pair(1,1));
	while(!q.empty()){
		pair<LL,LL>tp=q.front();
		q.pop();
		LL xx=tp.first,yy=tp.second;
		LL xx1,yy1;
		for(i=0;i<4;i++){
			xx1=xx+x[i];
			yy1=yy+y[i];
			if(xx1<1||xx1>h||yy1<1||yy1>w)continue;
			if(!c[xx1][yy1])continue;
			if(l[xx1][yy1]>l[xx][yy]+1){
				l[xx1][yy1]=l[xx][yy]+1;
				q.push(make_pair(xx1,yy1));
			}
		}
	}
	sum=h*w-l[h][w]-sumb-1;
	if(l[h][w]!=(LL)1e9)cout<<sum<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m,0);
for(int i  = 0; i < n; i++){
    int k;
    cin >> k;
    for(int i = 0; i < k; i++){
        int b;
        cin >> b;
        a[b - 1]++;
    }
}
int cnt = 0;
    for(int i = 0; i < m; i++){
        if(a[i] == n){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
#include <complex>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
using namespace std;

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

	int h, w; cin >> h >> w;
	vector<vector<int>> g(10, vector<int>(10));
	rep(i, 0, 10) rep(j, 0, 10) cin >> g[i][j];
	rep(k, 0, 10) rep(i, 0, 10) rep(j, 0, 10) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);

	int ans = 0;
	rep(i, 0, h) rep(j, 0, w) {
		int c; cin >> c;
		if (c != -1) ans += g[c][1];
	}

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


Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  string s;
  cin >> s;
  if(s[0] == s[2]) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n-1); i >= 0; --i)

const int MAX = 5e5+10;
int N, D, Q;
int d[MAX];
int pos[MAX];
int rev[MAX];
bool ans[MAX];

inline int move(int p, int d) {
    return min(p, abs(p-d));
}

inline int moveRev(int p, int d) {
    if (d/2 >= p) return p;
    return p+d;
}

int main() {
    cin >> N >> D;
    pos[0] = D;
    REP (i, N) {
        cin >> d[i];
        pos[i+1] = move(pos[i], d[i]);
    }

    rev[N] = 1;
    REPR (i, N) {
        rev[i] = moveRev(rev[i+1], d[i]);
    }

    REP (i, N) {
        ans[i] = pos[i] >= rev[i+1];
    }

    cin >> Q;
    REP (q, Q) {
        int i;
        cin >> i;
        cout << ((ans[i-1])?"YES":"NO") << endl;
    }
}


Measured memory_bytes: 8320
def main():
    A, B = map(int, input().split())
    # print(A, B)
    onesA = countOne(A)
    onesB = countOne(B)
    onesA += [0]*(len(onesB) - len(onesA))
    onesA = onesA
    onesB = onesB
    onesTot = [onesB[i]-onesA[i] for i in range(len(onesA))]
    b = format(A, "b")
    for i in range(len(b)):
        onesTot[i] += (b[len(b)-1-i] == "1")
    for i in range(len(onesTot)):
        onesTot[i] = str(onesTot[i] % 2)
    bfinal = "".join(onesTot[::-1])
    return int(bfinal, 2)

def countOne(n):
    # this counts 1 in each digit from 0 to n inclusive
    n = n + 1
    p = 2
    res = []
    while n >= p//2:
        d = n // p
        r = n % p
        res.append(d*(p//2)+max(0,(r-p//2)))
        p *= 2
    return res

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

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

namespace b
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var X = Console.ReadLine().Split(' ');
            int A = int.Parse(X[0]);
            int B = int.Parse(X[1]);
            int C = int.Parse(X[2]);
            int D = int.Parse(X[3]);
            while (true)
            {
                C = C - B;
                if(C <= 0)
                {
                    Console.WriteLine("Yes");
                    break;
                }
                A = A - D;
                if(A <= 0)
                {
                    Console.WriteLine("No");
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 17740
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 400


int main() {
	int a[N];
	f(i, N)a[i] = 0;
	int dp[N][N];
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	while (true) {
		scanf("%d", &n);
		if (n == 0)return 0;
		f(i, N) {
			f(j, N)dp[i][j] = 0;
			a[i] = 0;
		}
		f(i, n) {
			scanf("%d", &a[i]);
		}
		f(j, n+1) {
			for(int i=j-1;i>=0;i--){
				dp[i][j] = dp[i][j - 1];
				k = 2;
				while ((j - k) >= i) {
					if (dp[j - k + 1][j - 1] == (k - 2) && abs(a[j - k] - a[j - 1]) <= 1) {
						dp[i][j] = max(dp[i][j], dp[i][j - k] + k);
					}
					k += 2;
				}
}
		}
		printf("%d\n", dp[0][n]);
	}



	return 0;
}


Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        vector<int> score(n);
        for (int i = 0; i < n; i++) {
            cin >> score[i];
        }
        sort(score.begin(), score.end());

        int s = 0;
        for (int i = 1; i < n - 1; i++) {
            s += score[i];
        }
        cout << s / (n - 2) << endl;
    }

    return 0;
}

Measured memory_bytes: 3096
#include <iostream>

int main()
{
    int n;
    std::cin >> n;
    while (n > 0)
    {
        if (n % 10 == 7)
        {
            std::cout << "Yes" << std::endl;
            return 0;
        }
        n /= 10;
    }

    std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int main() {
	int i, j, k;

	int N, M, K;


	string s, t, u;
	cin >> s >> t >> u;
	
	char a = toupper(s[0]),b= toupper(t[0]),c= toupper(u[0]);

	cout << a << b << c;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main(void) {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1;
  int dy = y2 - y1;
  cout << x2 - dy << " " << y2 + dx << " " << x1 - dy << " " << y1 + dx << endl;

  return 0;
}

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

int main(){
	int n,ans=0,s=0;
	char x[12],y[12];
	scanf("%s",&x);
	while(x[s]!='\0')s++;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",&y);
		bool c=false;
		for(int j=0;j<10;j++){
			bool d=true;
			for(int k=0;k<s;k++){
				if(x[k]!=y[(j+k)%10]){d=false; break;}
			}
			if(d){c=true; break;}
		}
		if(c)ans++;
	}
	printf("%d\n",ans);
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll ll_pow(ll a, ll n){
    ll ans = 1;
    FOR(i, 0, n){
        ans *= a;
        ans %= 13;
    }
    return ans;
}

// a^b mod p
ll mod_pow(ll a, ll b){
    if(b==0) return 1;
 
    // 肩が奇数
    if(b%2==1){
        return a * mod_pow(a, b-1) % 13;
    }
    else{
        return mod_pow(a*a % mod, b/2) % 13;
    }
}

ll dp[100010][13];

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

    // input
    string s; cin >> s;
    ll L = s.size();

    // 左から0桁目
    char c = s[0];
    if(c=='?'){
        FOR(i, 0, 10){
            dp[0][i] = 1;
        }
    }else{
        ll v = c - '0';
        dp[0][v] = 1;
    }

    // 左からi桁目
    FOR(i, 1, L){
        char c = s[i];
        ll v;
        if(c=='?'){
            v = -1;
        }else{
            v = c - '0';
        }

        if(c=='?'){
            FOR(r, 0, 13){
                FOR(v, 0, 10){
                    // v
                    // ll j = (v * ll_pow(10, i) + r) % 13;
                    ll j = (r*10+v)%13;
                    dp[i][j] += dp[i-1][r];
                    dp[i][j] %= mod;
                }
            }
        }
        else{
            FOR(r, 0, 13){
                // v
                // ll j = (v * ll_pow(10, i) + r) % 13;
                ll j = (r*10+v)%13;
                dp[i][j] += dp[i-1][r];
                dp[i][j] %= mod;
            }
        }
    }

    // FOR(i, 0, 5){
    //     FOR(j, 0, 13){
    //         cout << dp[i][j] << ' ';
    //     }
    //     cout << endl;
    // }

    ll ans = dp[L-1][5];
    p(ans);
    
    return 0;
}

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

int main() {

  long long int n, k;
  cin >> n >> k;

  vector< pair< long long int, long long int > > v;

  for ( long long int i = 0; i < n; i++ ) {

    long long int a, b;
    cin >> a >> b;

    v.push_back( make_pair( a, b ) );

  }

  sort( v.begin(), v.end() );

  for ( long long int i = 0; k > 0; i++ ) {

    k -= v[i].second;
    if ( k <= 0 ) cout << v[i].first << endl;

  }

  return 0;

}


Measured memory_bytes: 2420
K, A, B = map(int, input().split())

def f():
    # A枚に達する
    a = A - 1
    # 増殖に使える時間
    b = K - a
    # A->Bにd回変換
    d, m = divmod(b, 2)
    return A + (B - A) * d + m

def g():
    return 1 + K

if (A + 2) < B:
    print(f())
else:
    print(g())


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 


ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}



int main()
{
     int n;
     cin>>n;
     ll a[n];
     for(int i=0;i<n;i++)cin>>a[i];
     sort(a,a+n);
     int ans=0;
     ll sum=0;
     for(int i=0;i<n-1;i++)
     {
          sum+=a[i];ans++;
          if(2*sum<a[i+1])ans=0;
     }
     ans++;
     cout<<ans;

}















 














 
 

















Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
// #define INF 1000000007
#define INF 10000000007
using namespace std;

ll recurse(int i,int val,vector<ll> &weights,vector<ll> &values,vector<vector<ll>> &dp)
{
    if( i <= 0 && val > 0) return INF;
    else if(i >= 0 && val == 0) return 0;
    else
    {
        if(dp[val][i] != -1) return dp[val][i];
        if(val-values[i-1] >=0)
            dp[val][i] = min(recurse(i-1,val-values[i-1],weights,values,dp)+weights[i-1],recurse(i-1,val,weights,values,dp));
        else
            dp[val][i] = recurse(i-1,val,weights,values,dp);
        return dp[val][i];
    }
}

int main(int argc, char const *argv[])
{
    int n, w;
    long long temp;
    cin >> n >> w;
    vector <ll> weights(n,0);
    vector <ll> values(n,0);
    ll total_v = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        weights[i] = temp;
        cin >> temp;
        total_v+= temp;
        values[i] = temp;
    }
    vector<vector<ll>> dp(total_v+1,vector<ll>(n+1,-1));
    for (int i = 0; i <= total_v; i++)
    {
        //cout << "Value is: " << i << endl;
        dp[i][n] = recurse(n,i,weights,values,dp);
        //cout << dp[i][n] << endl;
    }
    for (int i = total_v; i >=0 ; i--)
    {
        if(dp[i][n] <= w)
        {
            cout << i;
            break;
        }
    }
    
    // cout << total_v << endl;
    // for (int i = 0; i <= total_v; i++)
    // {
    //     for (int j = 0; j <= n; j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    //     //cout << dp[i][n] << endl;
    // }
                             
    return 0;
}


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

using namespace std;

int main(){
    int d,g,ans=1e9;
    cin>>d>>g;
    vector<int> p(d),c(d);

    for(int i=0;i<d;i++){
        cin>>p[i]>>c[i];
    }

    for(int i=0;i<(1<<d);i++){
        int sum=0;
        int maxvalue=0;
        int cnt=0;
        for(int j=0;j<d;j++){
            if((i>>j)&1){
                sum+=100*(j+1)*p[j]+c[j];
                cnt+=p[j];
            }
            else
                maxvalue = j;
        }

        if(sum<g){
            int num = 100*(maxvalue+1);
            int tmp;
            if(g-sum<=num){
                tmp = 1;
            }
            else
                tmp = (g-sum)/num;

            if(tmp>=p[maxvalue])continue;

            cnt+=tmp;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
#define ll long long
#define ld long double
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int N; cin >> N;
  string S; cin >> S;
  int flag = 1;
  if (N % 2 == 1) {
   cout << "No" << endl;
   return 0;
  } else {
    rep(i, N/2) {
      if (S[i] != S[i+N/2]) {
        flag = 0;
      }
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No"  << endl;
  }
  return 0;
}


Measured memory_bytes: 256
mod = 998244353
s = list(map(int, list(input())))
n = len(s)
dp = [[0]*(sum(s)+1) for _ in range(2*n+1)]
dp[0][0] = 1
curr = curb = 0
for i in range(2*n):
  if i < n:
    curb += s[i]
    curr += 2 - s[i]
  for j in range(min(i, curb)+1):
    if dp[i][j]:
      dp[i][j] %= mod
      if i - j < curr:
        dp[i+1][j] += dp[i][j]
      if j < curb:
        dp[i+1][j+1] += dp[i][j]
print(dp[2*n][curb] % mod)   

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

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 100;

int main()
{
    int N, X;
    cin >> N >> X;
    int sum = 0;
    int m;
    int ans = maxn;
    for(int i = 0; i < N; i ++)
    {
        cin >> m;
        if(ans > m) ans = m;
        sum += m;
    }
    int remain = X - sum;
    int cnt = remain / ans;
    cout << N + cnt << endl;
    return 0;
}


Measured memory_bytes: 256
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	string S;
	cin >> S;
	
	// 解法
	ll best_length = 0;
	ll length = 0;
	REP(i,S.size()){
		if (S[i]=='A' | S[i]=='T' | S[i]=='G'|S[i]=='C')length++;
		else length = 0;
		if (length>best_length) best_length = length;
	}
	
	//出力
	cout << best_length << endl;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s; cin >> s;
    vector<int> ans(s.size(),0);

    rep(i,s.size()){
        if(s[i]=='R'){
            int idx=1;
            int ct[2]={};
            ct[idx%2]++;
            while(i+1<s.size() and s[i]==s[i+1]){
                idx++;
                ct[idx%2]++;
                i++;
            }
            if(idx%2==1){ //Rが連続しているのが偶数個なら
                ans[i+1]+=ct[0];
                ans[i]+=ct[1];
            }else {
                ans[i+1]+=ct[1];
                ans[i]+=ct[0];
            }
        }
    }

    reverse(all(s));
    reverse(all(ans));

    rep(i,s.size()){
        if(s[i]=='L'){
            int idx=1;
            int ct[2]={};
            ct[idx%2]++;
            while(i+1<s.size() and s[i]==s[i+1]){
                idx++;
                ct[idx%2]++;
                i++;
            }
            if(idx%2==1){
                ans[i+1]+=ct[0];
                ans[i]+=ct[1];
            }else {
                ans[i+1]+=ct[1];
                ans[i]+=ct[0];
            }
        }
    }
    reverse(all(ans));
    rep(i,s.size()){
        if(i)cout <<" ";
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 1104
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (A, B) = read!(i32, i32);
    println!("{}", if (A * B) % 2 == 0 { "No" } else { "Yes" })
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

template <typename T>
void readVec(vector<T>& v, int n)
{
	for(int i = 0; i < n; ++i)
			cin >> v[i];
}

int main()
{
	double n; cin >> n;
	cout << setprecision(9) << (2 * 3.14159 * n ) ;
    return 0;
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
const long double PI=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int read() {
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
int main(){
    char c[10];cin>>c;
    cout<<((c[0]!='Y' || c[1]!='A' || c[2]!='K' || c[3]!='I')?"No\n":"Yes\n");
    return 0;
}

Measured memory_bytes: 256
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    u32 n;
    std::cin >> n;
    n%=10;

    std::string ans;

    if (n==3) ans = "bon";
    else if (n==0||n==1||n==6||n==8)ans = "pon";
    else ans = "hon";

    std::cout << ans << '\n';
}


Measured memory_bytes: 3640
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var k, x int

	fmt.Scanf("%d %d", &k, &x)

	fmt.Println(toString(logic(k, x), " "))
}

func logic(k, x int) []int {
	min := -1000000
	max := 1000000
	result := []int{x}

	for i := 1; i < k; i++ {
		a := x + i
		b := x - i
		if max >= a && min <= a {
			result = append(result, a)
		}
		if max >= b && min <= b {
			result = append(result, b)
		}
	}
	sort.Ints(result)
	return result
}

func toString(nums []int, delim string) string {
	return strings.Trim(strings.Replace(fmt.Sprint(nums), " ", delim, -1), "[]")
}


Measured memory_bytes: 640
def calc_m_value(M, A, B, N, h):
    return min([M[h - A[i]]+B[i] if A[i] <= h else B[i] for i in range(N)])

H, N = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

M = [0] * (H+1)
for i in range(1, H+1):
    M[i] = calc_m_value(M, A, B, N, i)

print(M[H])


Measured memory_bytes: 3484
#include <bits/stdc++.h>
typedef long long ll; 
typedef unsigned long long ull;
const ull mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

void solve() {
    int n, k; sc(n); sc(k);
    int a[n]; fo(i, n) sc(a[i]);
    int g = 0;
    int el = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (a[i] > a[j]) g++;
            else if (a[i] < a[j]) el++;
        } 
    }
    ull num1 = (ull) k * (k+1);
    num1 /= 2; num1 %= mod;
    ull num2 = (ull) k * (k-1);
    num2 /= 2; num2 %= mod;
    num1 *= (ull) g; num1 %= mod;
    num2 *= (ull) el; num2 %= mod;
    ull ans = (num1 + num2) % mod;
    cout << ans;
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int n;

void dfs(string s,int mx){
    if(s.size()==n) cout << s << endl;
    else{
        for(int i='a';i<=mx+1;i++){
            string t = s;
            t.push_back(i);
            dfs(t,max(i,mx));
        }
    }
}

int main(){
    cin >> n;
    dfs("",'a'-1);
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N, M, X; cin >> N >> M >> X;
  vector<int> A(M); cin >> A;
  int v1 = 0, v2 = 0;
  for (int i = 0; i < M; ++i) {
    if (A[i] < X) ++v1;
    else          ++v2;
  }
  cout << min(v1, v2) << endl;
}


Measured memory_bytes: 3624