akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }


int n;
int a[200005];
void solve() {
    cin >> n;
    rep(i, n) cin >> a[i];

    int ans = 0;
    int pos = 1;
    rep(i, n) {
        if (a[i] != pos) {
            ++ans;
        }
        else {
            ++pos;
        }
    }

    if (pos != n + 1 - ans || ans == n) cout << -1 << endn;
    else cout << ans << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>

/*
max(N- [x2, ..., xN] [ 1 2 3 4 ... 4 3 2], 0)

(1 + z + z^2 + ... + z^N) (1 + z^2 + z^4 + ... + z^{2N}) ...
f(z) = 1/[(1-z){(1-z^2)(1-z^3)...(1-z^{N/2})}^2]


[z^N] (N f(z) - z * f'(z))/(1-z)
[z^N] (f(z)(N - z * f'(z)/f(z)))/(1-z)

f'(z)/f(z) = 1/(1-z) + 2(2z/(1-z^2) + 3z^2/(1-z^3) + ...

log f = \sum_{i=2}^{N/2}

f(z) = (1-z)(1-z^{N/2+1})^2(1-z^{N/2+2})^2... / [(1-z)(1-z^2)...]^2
f(z) = (1-z)(1-2z^{N/2+1})(1-2z^{N/2+2})... / [(1-z)(1-z^2)...]^2
f(z) = (1-z)(1-2z^{N/2+1}-2z^{N/2+2}-...) / [(1-z)(1-z^2)...]^2

*/

int n, m;

int dp[5001];

int main(){
  scanf("%d%d", &n, &m);

  dp[0] = 1;
  for(int i = (n+1)/2+1; i <= n; i++){
    dp[i] = m - 2;
  }
  for(int i = n; i >= 1; i--){
    dp[i] -= dp[i-1];
    if(dp[i] < 0) dp[i] += m;
  }
  if(n & 1){
    for(int i = n; i >= (n+1)/2; i--){
      dp[i] -= dp[i-(n+1)/2];
      if(dp[i] < 0) dp[i] += m;
    }
  }
  for(int i = 0; i <= n; i++){
    for(int j = 1; ; j++){
      int k = j * (3 * j - 1) / 2;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
      k += j;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
    }
  }
  for(int i = 0; i <= n; i++){
    for(int j = 1; ; j++){
      int k = j * (3 * j - 1) / 2;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
      k += j;
      if(k > i) break;
      if(j&1){
        dp[i] += dp[i - k];
        if(dp[i] >= m) dp[i] -= m;
      }
      else {
        dp[i] -= dp[i - k];
        if(dp[i] < 0) dp[i] += m;
      }
    }
  }

/*
  for(int i = 0; i <= n; i++) dp[i] = 1;
  for(int i = 2; i <= n/2; i++){
    for(int j = i; j <= n; j++){
      dp[j] += dp[j-i];
      if(dp[j] >= m) dp[j] -= m;
    }
    for(int j = i; j <= n; j++){
      dp[j] += dp[j-i];
      if(dp[j] >= m) dp[j] -= m;
    }
  }
 

  if(n & 1){
    for(int j = (n+1)/2; j <= n; j++){
      dp[j] += dp[j-(n+1)/2];
      if(dp[j] >= m) dp[j] -= m;
    }
  }
*/

  int c = 0;
  for(int i = 0; i <= n; i++){
    c = (c + (long long) (n - i) * dp[i]) % m;
  }

  printf("%d\n", c);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
#define nl '\n'
typedef long long ll;
typedef long double ld;
//////////////////////////////////////////////////////////////////////



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

  string s;cin>>s;
  cout << s.substr(0,s.length()-8) << endl;
  
  return 0;
};


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

int32_t main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]==',')
        cout<<" ";
        else
        cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 3604
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func toInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func main() {
	lst := make([]int, 0)
	for i := 0; i < 10; i++ {
		lst = append(lst, toInt(readLine()))
	}
	sort.Ints(lst)
	for i := 9; i > 6; i-- {
		fmt.Println(lst[i])
	}
}


Measured memory_bytes: 6576
#include <bits/stdc++.h>
typedef int integer;
#define int long long
#define pb push_back
#define mp make_pair
#define sz(x) (int) x.size()
#define mod 1000000007
using namespace std;


int ar[100000];
int n;

int check(int x){

    int ans = 0;
    for (int i = 0; i < n; i++){
        ans += (ar[i] == x || ar[i] + 1 == x || ar[i] - 1 == x);
    }
    return ans;
}

integer main() {
    ios_base::sync_with_stdio(false);

    cin >> n;
    map<int, int> M;
    for (int i = 0; i < n; i++){
        cin >> ar[i];
        M[ar[i]]++;
        M[ar[i] + 1]++;
        M[ar[i] - 1]++;
    }

    int ans = 0;
    for (auto z : M){
        ans = max(ans, z.second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 7040
#include <stdio.h>

#define WHITE 1
#define GRAY 0
#define BLACK -1
#define INF 100000000

void bfs(int);
void enqueue(int);
int dequeue(void);

int Q[102],d[102],color[102],time,n,vv[102][102],k[102];
int head, tail;

int main()
{
  int i,j,u,min;

  scanf("%d",&n);

  head = 0;
  tail = 1;

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

    for(j=0;j<k[u];j++){
      scanf("%d",&vv[u][j]);
    }
  }

  bfs(1);
  for(i=1;i<=n;i++)  {
    if(d[i]==INF) d[i]=-1;
    printf("%d %d\n",i,d[i]);
  }

  return 0;
}

void bfs(int s){
  int i,u,v;
  for (u=1;u<=n;u++){
    color[u] = WHITE;
    d[u] = INF;
  }
  color[s] = GRAY;
  d[s] = 0;
  // Q = empty;
  enqueue(s);

  while(head!=tail){
    u = dequeue();
    for(i=0;i<k[u];i++){
      v=vv[u][i];
      if (color[v] == WHITE){
	color[v] = GRAY;
	d[v] = d[u] + 1;
	enqueue(v);
      }
      color[u] = BLACK;
    }
  }
}

void enqueue(int x){ /* キューの末尾に要素 x を追加 */
  Q[tail] = x;
  if (tail + 1 == n) tail = 0;
  else tail++;
}

int dequeue(void){ /* キューの先頭から要素を取り出す */
  int x;
  x = Q[head];
  if (head + 1 == n) head = 0;
  else head++;
  return x;
}

Measured memory_bytes: 632
N, K = map(int, input().split())
S = input()

ans = 0
for i in range(N):
    if S[i] == 'L':
        if i - 1 < 0:
            continue
        if S[i - 1] == 'L':
            ans += 1
    else:
        if i + 1 >= N:
            continue
        if S[i + 1] == 'R':
            ans += 1


X = (len([s for s in S.split('L') if s != '']) + len([s for s in S.split('R') if s != '']))
ans += min(X, K) * 2
print(min(ans, N - 1))


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

using namespace::std;

int ans = 0;

void solve(int** osenbei, int** osenbei_extra, int i, const int c, const int r, int temp){

  int bef = 0;
  int aft = 0;
  if(i == c){

	for(int j = 0; j < c; j++){
	  for(int k = 0; k < r; k++){
		osenbei_extra[j][k] = osenbei[j][k];
	  }
	}

	for(int j = 0; j < r; j++){

	  int bef = 0;
	  int aft = 0;
	  for(int k = 0; k < c; k++){//i???????????????
		if(osenbei_extra[k][j] == 1){
		  osenbei_extra[k][j] = 0;
		  bef++;//i?????????1?????°????????????
		}
		else{
		  osenbei_extra[k][j] = 1;
		  aft++;//i?????????0?????°????????????
		}
	  }
	  if(bef <= aft){
		temp = temp - bef + aft;
		ans = max(ans, temp);
	  }
	  else{
		for(int k = 0; k < c; k++){//i?????????????????´???
		  if(osenbei_extra[k][j] == 1) osenbei_extra[k][j] = 0;
		  else osenbei_extra[k][j] = 1;
		}
	  }
	}

	if(ans < temp){
	  ans = temp;
	}

  }
  else{

	for(int j = 0; j < r; j++){//i???????????????
	  if(osenbei[i][j] == 1){
		osenbei[i][j] = 0;
		bef++;//i?????????1?????°????????????
	  }
	  else{
		osenbei[i][j] = 1;
		aft++;//i?????????0?????°????????????
	  }
	}

	solve(osenbei, osenbei_extra, i+1, c, r, temp - bef + aft);

	for(int j = 0; j < r; j++){//i?????????????????´???
	  if(osenbei[i][j] == 1) osenbei[i][j] = 0;
	  else osenbei[i][j] = 1;
	}

	solve(osenbei, osenbei_extra, i+1, c, r, temp);

  }
}

int main(){

  while(1){

	int temp_c, temp_r;
	cin >> temp_c;//???
	cin >> temp_r;//???

	const int r = temp_r;
	const int c = temp_c;

	if(c == 0 && r == 0) break;	

	int** osenbei = new int*[c];
	int** osenbei_extra = new int*[c];
	for(int i = 0; i < c; i++){
	  osenbei[i] = new int[r];
	  osenbei_extra[i] = new int[r];
	}

	for(int i = 0; i < c; i++){
	  for(int j = 0; j < r; j++){
		osenbei[i][j] = 0;
		osenbei_extra[i][j] = 0;
	  }
	}

	int temp = 0;
	for(int i = 0; i < c; i++){
	  for(int j = 0; j < r; j++){
		cin >> osenbei[i][j];
		if(osenbei[i][j] != 0 && osenbei[i][j] != 1) return 1;
		else if(osenbei[i][j] == 1) temp++;
		osenbei_extra[i][j] = osenbei[i][j];
	  }
	}
	ans = temp;

	solve(osenbei, osenbei_extra, 0, c, r, temp);//??±???????????¢?´¢+????¬????
	cout << ans << endl;

  }

  return 0;

}

Measured memory_bytes: 2396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var firstLine = Console.ReadLine().Split(' ').Select(value => long.Parse(value)).ToList();
			var n = firstLine[0];
			var aList = Console.ReadLine().Split(' ').Select(value => long.Parse(value)).ToList();

			foreach(var a in aList)
			{
				n -= a;
			}

			Console.WriteLine(n >= 0 ? n : -1);
		}
	}
}


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

using namespace std;

int main()
{
    string S, T;
    cin >> S;
    cin >> T;

    int len = S.size();
    int res = 0;
    for (int i = 0; i < len; ++i) {
        if (S[i] != T[i]) {
            res ++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3448
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  vector<int> mochi(N);
  for(int i = 0; i < N; i++){
    cin >> mochi.at(i);
  }
  
  int max_all, count = N;
  for(int i = 0; i < N; i++){
    int max1 = 0;
    
    for(int j = 0; j < N; j++){
      max1 = max(max1, mochi.at(j));
    }
    
    for(int j = 0; j < N; j++){
      if(max1 == mochi.at(j)){
        mochi.at(j) = 0;
        break;
      }
    }
    
    if(max1 == max_all){
      count--;
    }
    
    max_all = max1;
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,arr[10005];
	cin>>n;
	for(int i =0;i<n;i++)
	{
		int t;
		cin>>t;
		arr[i]=t;
	 } 
	 for(int i=n-1;i>=0;i--)
	 {
	 	if(i==0)
	 		cout<<arr[i];
	 	else
	 	cout<<arr[i]<<" ";
	 }
	 cout<<endl;
	return 0;
} 


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ao=a/d;
  if(ao*d<a)ao++;
  int ta=c/b;
  if(ta*b<c)ta++;
  if(ta<=ao){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3652
s = input()
point = 0
p = 0
for l in s:
	if l == "g":
		if p > 0:
			p -= 1
			point += 1
		else:
			p += 1
	else:
		if p > 0:
			p -= 1
		else:
			point -= 1
			p += 1
print(point)

Measured memory_bytes: 3316
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;

int main() {
  string A, B, C;

  cin >> A >> B >> C;
  A = toupper(A[0]);
  B = toupper(B[0]);
  C = toupper(C[0]);

  cout << A << B << C << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#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()

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  string A[7]={"SUN","MON","TUE","WED","THU","FRI","SAT" };
  REP(i,7)if(S==A[i]){
    cout<<7-i<<endl;
    break;
  }
  return 0;
}


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

int findSum(int n){
	int s = 0;
	while(n){
		s+=(n%10);
		n/=10;
	}
	return s;
}

int  main(){
	int n,a,b;
	cin>>n>>a>>b;
	long long aula = 0;
	for(int i = 1 ; i <= n ;i++){
		if(findSum(i)>=a && findSum(i)<=b){
			aula+=i;
		}
		else continue;
	}
	
	cout<<aula<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int selectionSort(int A[], int N) {
  int i, j, t, sw = 0, mini;
  for ( i = 0; i < N - 1; i++ ) {
    mini = i;
    for ( j = i; j < N; j++ )
      if ( A[j] < A[mini] ) mini = j;
    t = A[i]; A[i] = A[mini]; A[mini] = t;
    if ( i != mini ) sw++;
  }
  return sw;
}

int main() {
  int A[100], N, i, sw;

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

  sw = selectionSort(A, N);

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

  return 0;
}


Measured memory_bytes: 2752
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

ll gcd(ll x, ll y){
  if(x%y==0){
    return y;
  }else{
    return(gcd(y,x%y));
  }
}
ll lcm(ll x, ll y){
  return x*y/gcd(x,y);
}
int c(int x){
  int ans=0;
  while(x%2==0){
    x/=2;
    ans++;
  }
  return ans;
}
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
    a[i]/=2;
  }
  ll x=1;
  rep(i,n){
    x = lcm(x,a[i]);
  }
  vector<int> count(n);
  rep(i,n) count[i] = c(a[i]);
  bool ok=true;
  rep(i,n-1) if(count[i]!=count[n-1]) ok = false;
  if(x>m||!ok) cout << 0 << endl;
  else{
    int ans = m / x;
    ans = (ans+1)/2;
    cout << ans << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[n - 1] - a[0];
}

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

string i2s(int x){
  stringstream ss;
  ss<<x;
  string tmp;
  ss>>tmp;
  return tmp;
}

bool check(int x){
  if(x<0)return false;
  string str=i2s(x);
  string tmp=str;
  reverse(str.begin(),str.end());
  return (str==tmp);
}

int main(){
  int x;
  cin>>x;
  for(int i=0;i<=10000;i++){
    if( check(x-i) ){
      cout<<x-i<<endl;
      break;
    }
    if( check(x+i) ){
      cout<<x+i<<endl;
      break;
    }
  }
  return 0;
}

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

int main() {
  vector<int>  antena(5);
  int k;
  for(int i=0;i<5;i++){
    cin >> antena.at(i);
  }
  cin >> k;
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      if( abs( antena.at(i)-antena.at(j) ) > k){
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
        
  
  return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 50;

vector<string> q;

string now, aa, bb;
vector<bool> used;
int ans = 0;

void rec(int id, int n) {
	if (id == n) {
		if (now >= aa && now <= bb) ans++;
		return;
	}

	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			used[i] = true;
			now.pb((char)(i + '0'));
			rec(id + 1, n);
			used[i] = false;
			now.pop_back();
		}
	}
}

string get(vector<int>& a) {
	string res;
	for (int i : a) res.pb((char) (i + '0'));
	return res;
}

void solve() {
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	aa = get(a);
	bb = get(b);
	if (aa > bb) swap(aa, bb);
	used.resize(n + 1);
	rec(0, n);
	cout << ans - 1;
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
// ABC043 B - バイナリハックイージー
#include <stdio.h>

void pop(char *str, int *top) {
    if (*top == 0) {
        return;
    }
    *top -= 1;
    return;
}

void push(char *str, int *top, char c) {
    str[*top] = c;
    *top += 1;
    return;
}

int main(void) {
    char S[11];
    char result[11];
    // input 
    scanf("%s", S);

    int i = 0;
    int top = 0;
    while(S[i] !='\0') {
        if (S[i] == 'B') {
            pop(result, &top);
        } else {
            push(result, &top, S[i]);
        }
        i++;
    }
    result[top] = '\0';
    // output
    printf("%s\n", result);

    return 0;

}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n,cnt=0;
  string s,t;
  cin >> n >> s >> t;
  for(int i=1; i<=n; i++) {
    if(s.substr(n-i)==t.substr(0,i)) {
      cnt=max(cnt,i);
    }
  }
  cout << n*2-cnt << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

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

int main()
{
    cout << fixed << setprecision(15);
    ll a, b, c;
    cin >> a >> b >> c;

    if(b-a == c-b){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
h, w, d = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]

L = [[0, 0] for _ in range(h*w)]
for i in range(h):
    for j in range(w):
        id = A[i][j]
        id -= 1
        L[id][0] = i
        L[id][1] = j

C = [0]*(h*w)
for i in range(h*w):
    ni = i+d
    if ni <= h*w-1:
        C[ni] = C[i]+abs(L[ni][0]-L[i][0])+abs(L[ni][1]-L[i][1])
#print(C)

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    l, r = l-1, r-1
    print(C[r]-C[l])


Measured memory_bytes: 20676
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n,cnt=1;
    double vx[51],vy[51];
    while(cin>>n,n){
        rep(i,n) cin>>vx[i]>>vy[i];
        int ans=0;
        rep(i,n) ans += vx[i]*vy[(i+1)%n]-vx[(i+1)%n]*vy[i];
        cout<<cnt++<<" "<<fixed<<setprecision(1)<<abs(ans)*0.5<<endl;
    }
    return 0;
}

Measured memory_bytes: 3272
s = input()

if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
elif s == 'SAT':
    print(1)

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split(' '))
MOD = 10**9 + 7

n = N-K+1
print(n)
for i in range(2,K+1):
	n = (n * (N-K+2-i) * (K-i+1) // (i * (i-1)))
	print(n % MOD)

Measured memory_bytes: 3316
#ifndef CLion
//#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;

void Main(){
    ll a , b , c , k;
    cin >> a >> b >> c >> k;

    ll mx = 0 , mn;

    mn = min(a , k); k -= mn; mx += mn;
    mn = min(b , k); k -= mn;
    mn = min(c , k); mx -= mn;

    cout << mx;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef CLion
    freopen( "in.txt" , "r" , stdin  );
    //freopen( "out.txt", "w" , stdout );
#endif

    int t = 1;
    //cin >> t;
    while ( t-- ) Main();
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <math.h>
int i,j,k;
using namespace std;
void ABC110(void);
void ABC111(void);
void ABC112(void);
void ABC113(void);
void ABC114(void);
void ABC115(void);
void ABC116(void);
void ABC117(void);
void ABC118(void);
void ABC119(void);

int main(void){
    ABC115();
}

void ABC115(){
    int n,sum=0;
    cin>>n;
    vector<int> vec(n);
    for(i=0;i<n;i++){
        cin>>vec[i];
        sum+=vec[i];
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    cout<<sum-vec[0]/2<<endl;
}

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



struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key)return u;
  if(k<u->key)return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL) return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  /* if(z->left==NIL || z->right ==NIL){
    y=z;
  }
  else{
    y=treeSuccessor(z);
  }
  if(y->left!=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }
  else if(y==y.parent.left){
    y.parent.left=x;
  }
  else{
    y.parent.right=x;
  }
  if(y!=z){
  z->key=y->key;*/
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else if (z->key < y->key){
      y->left=z;
  }
  else{
    y->right=z;
  }
  
  return;
}

void inorder(Node u){
  if(u->left!=NIL) inorder(u->left);
  printf(" %d",u->key);
  if(u->right!=NIL)  inorder(u->right);
  

}
void preorder(Node u){
printf(" %d",u->key);
if(u->left!=NIL) preorder(u->left);
if(u->right!=NIL)  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
N, x = map(int, input().split(' '))
candy_num = list(map(int, input().split(' ')))

candy_num.sort()

sum_want = 0
num_child = 0

for i in range(N):
    sum_want += candy_num[i]
    if i == N-1 and sum_want < x:
        break
    if sum_want > x:
        break
    else:
        num_child += 1

print(num_child)

Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    string S, T, U;
    int A, B;

    cin >> S >> T >> A >> B >> U;

    if(S==U) {
        cout << A-1 << " " << B << endl;
    } else if(T==U) {
        cout << A << " " << B-1 << endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200009
#define pb push_back
using namespace std;
typedef long long ll;
void slv()
{
    ll k;
    cin>>k;
    string s="";
    for(ll i=0;i<10000000;i++) s+="7";
    ll r=0LL;
    for(ll i=0;i<10000000;i++) {
        r=r*10LL + (s[i]-'0'); //cout<<s[i]<<" X "<<r<<endl;
        r%=k; //cout<<r<<" r\n";
        if(r==0) {
            cout<<i+1<<endl;
            return ;
        }
    }
    puts("-1");
}
int main()
{
    int t;
    t=1;
    for(int cs=1;cs<=t;cs++)
    {
        //printf("Case #%d: ",cs);
        slv();
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

ll N;

int rec(ll s){
    if(s>N) return 0;
    int ret = 0;
    string str=to_string(s);
    //sが753数かどうか
    //7の数+5の数+3の数==sの長さ && それぞれが1以上かどうか
    int th,fi,se;
    th = fi = se = 0;
    for(int i=0;i<str.length();i++){
        if(str[i]=='3') th++;
        if(str[i]=='5') fi++;
        if(str[i]=='7') se++;
    }
    if(th>0 && fi>0 && se>0)ret = 1;
    ret += rec(s*10+3);
    ret += rec(s*10+5);
    ret += rec(s*10+7);
    return ret;
}
int main(){
    cin >> N;
    cout << rec(0) << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];

    // 各文字列に含まれる"AB"の数を数える
    vector<ll> cnt(n);
    rep(i, n){
        for(ll pos=0; pos<s[i].size()-1; pos++){
            if(s[i][pos] == 'A' && s[i][pos+1] == 'B') cnt[i]++, pos++;
        }
    }
    ll ans = 0;
    ll bCnt = 0, aCnt = 0, abCnt = 0;
    rep(i, n){
        ans += cnt[i];
        if(s[i][0] == 'B') (s[i][s[i].size()-1] == 'A') ? abCnt++ : bCnt++;
        else if(s[i][s[i].size()-1] == 'A') aCnt++;
    }
    cout << ans + (aCnt+bCnt == 0 && abCnt > 0 ? abCnt-1 : abCnt+min(aCnt, bCnt)) << endl;
}

Measured memory_bytes: 3760
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;


int main(){ 
    int a, b;
    cin >> a >> b;
    int x = 0;
    for (int i=1;i< b - a; i++) x += i;
    cout << x - a << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
 
int main(void) {
    string date = "2019/04/30";
    string s;
    cin >> s;
    if(s <= date){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};



int main(){
 
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    bool ok = false;
    rep(i,k){
        if(a < b && b < c){
            ok = true;
        }
        if(a >= b){
            b = b*2;
        }else if(b >= c){
            c = c*2;
        }
    }
    if(a < b && b < c){
        ok = true;
    }
 
    if(ok) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3132
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=sc.nextInt();
		}
		
		int[] dp=new int[n];
		dp[0]=0;
		
		for(int i=1;i<n;i++) {
			
			int sum=0;
			for(int j=i-1;j>=0;j--) {
				sum+=(arr[i] * arr[j]);
			}
			
			dp[i]=dp[i-1]+sum;
		}
		
		System.out.println(dp[n-1]);
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <map>
#include <string>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int f(string const & s){
    int p = 0, res = 0;
    while(p < (int)s.size()){
        int n = 0;
        while(isdigit(s[p])){
            n *= 10;
            n += s[p]-'0';
            p++;
        }
        n += n==0;
        int m[256];
        m[(int)'m'] = 1000;
        m[(int)'c'] = 100;
        m[(int)'x'] = 10;
        m[(int)'i'] = 1;
        res += m[(int)s[p]] * n;
        p++;
    }
    return res;
}

string g(int n){
    string res;
    char c[] = "ixcm";
    rep(i,4){
        int k = n%10;
        n /= 10;
        if(k == 0) continue;
        res += c[i];
        if(k!=1) res += k+'0';
    }
    rep(i,res.size()/2) swap(res[i], res[res.size()-1-i]);
    return res;
}

int main(){
    int n;
    cin >> n;
    rep(i,n){
        string s, t;
        cin >> s >> t;
        cout << g(f(s)+f(t)) << endl;
    }
}

Measured memory_bytes: 1200
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan =new Scanner(System.in);
    		
    		int n=Integer.parseInt(scan.next());
    		int i=Integer.parseInt(scan.next());
    		System.out.print(n-i+1);
   
     
    }
    }
// end 

Measured memory_bytes: 21972
L, R = map(int, input().split())
# min = float("inf")
# for i in range(L, R + 1):
# 	for j in range(i + 1, R + 1):
# 		mod = ((i % 2019) * (j % 2019)) % 2019
# 		if min > mod:
# 			min = mod

# 2019 = 3 * 673

if R - L >= 2019:
	print(0)
else:
	R %= 2019
	L %= 2019
	if L > R:
		R += 2019
	min = float("inf")
	for i in range(L, R + 1):
		for j in range(i + 1, R + 1):
			mod = ((i % 2019) * (j % 2019)) % 2019
			if min > mod:
				min = mod
	print(min)

# 2020 2040 -> 1 21
# 2010 2030 -> 2010 11


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
 
 
int main() {
 
    int judge[1000000];
    for(int k=0;k<1000000;k++)judge[k]=1;
    int a,d,n,i,j,sum,judge2=0;
    set<int> prime;
    
    prime.insert(2);
    
    //999999までの素数リストをつくる。
    for(i=3;i<999999;i+=2){
    	if(judge[i]==1){
    		prime.insert(i);
    		for(j=2;j<=1000000/i;j++){
    			judge[i*j] = 0;
    		}
    	}
    }
    
    
    
    while(1){
    	    sum = 0;
    	    cin >>a>>d>>n;
    	    if (a==0&&d==0&&n==0)break;
    	    
    	    i = 0;
    	    while(1){
    	    	if (prime.find(a+i*d)!=prime.end()){
    	    		sum++;
    	    		if(sum==n){
    	    			cout << a+i*d << endl;
    	    			break;
    	    		}
    	    	}
    	    	i++;
    	    }
    }
 
    return 0;
}

Measured memory_bytes: 8776
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;


int main(void) {
	int n, i, a[100003], ct, ans = 0;
	set<int> s;
	set<int>::iterator it;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		s.insert(a[i]);
	}

	sort(a, a + n);

	for (it = s.begin(); it != s.end(); it++) {
		ct = upper_bound(a, a + n, *it) - lower_bound(a, a + n, *it);
		if (ct > *it) ans += ct - *it;
		if (ct < *it) ans += ct;
	}

	cout << ans << endl;

	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  int h, w;
  while (cin >> h >> w) {
    char g[h][w];
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> g[i][j];
      }
    }
    int i = 0;
    int j = 0;
    while (true) {
      if (g[i][j] != '#') break;
      g[i][j] = '@';
      if (i == h - 1 && j == w - 1) break;
      if (i + 1 < h && g[i + 1][j] == '#') {
        ++i;
        continue;
      }
      if (j + 1 < w && g[i][j + 1] == '#') {
        ++j;
        continue;
      }
      g[0][0] = '#';
      break;
    }
    cout << (i == h  - 1 && j == w - 1 && count(&g[0][0], &g[h - 1][w - 1] + 1, '#') == 0 ? "Possible" : "Impossible") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
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;}



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

int a,b,c;
cin >> a >> b >> c;
if((a == b && b != c)||(a == c && b != c)||(c == b && a != c)) cout << "Yes" << endl;
else cout << "No" << endl;





//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var s = Console.ReadLine();
        var k = int.Parse(Console.ReadLine());
        List<string> res = new List<string>();
        for (int i = 0; i < s.Length; i++)
        {
            var max = Min(k, s.Length - i);
            for (int j = 1; j <= max; j++)
            {
                res.Add(s.Substring(i, j));
            }
        }
        Console.WriteLine(res.Distinct().OrderBy(x => x).Take(k).Last());
    }
}


Measured memory_bytes: 13664
import java.util.*;

public class Main{

    int w,h;
    int[][] map;
    int sx,sy,gx,gy;
    int ans;
    int[] dx = {0,1,0,-1};
    int[] dy = {-1,0,1,0};

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            w = sc.nextInt();
            h = sc.nextInt();
            if(w==0 && h==0) break;

            map = new int[h][w];
            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    map[i][j] = sc.nextInt();
                    if(map[i][j]==2){
                        sx = j;
                        sy = i;
                    }
                    if(map[i][j]==3){
                        gx = j;
                        gy = i;
                    }
                }
            }

            ans = Integer.MAX_VALUE;
            dfs(sx,sy,0);

            if(ans>10) ans = -1;
            System.out.println(ans);
        }
    }

    void dfs(int x, int y, int cnt){
        if(x==gx && y==gy){
            ans = Math.min(ans,cnt);
            return;
        }
        if(cnt>=10) return;

        int nx = x, ny = y;
        for(int i=0; i<4; i++){
            nx = x+dx[i]; ny = y+dy[i];
            if(nx<0 || nx>=w || ny<0 || ny>=h || map[ny][nx]==1) continue;
            boolean goal = false, end = false;
            while(true){
                if(nx==gx && ny==gy){
                    ans = Math.min(ans,cnt+1);
                    goal = true;
                    break;
                }
                if(nx+dx[i]<0 || nx+dx[i]>=w || ny+dy[i]<0 || ny+dy[i]>=h){
                    end = true;
                    break;
                }
                if(map[ny+dy[i]][nx+dx[i]]==1) break;
                nx += dx[i];
                ny += dy[i];
            }
            if(goal || end) continue;
            boolean change = false;
            if(map[ny+dy[i]][nx+dx[i]]==1){
                map[ny+dy[i]][nx+dx[i]] = 0;
                change = true;
            }
            dfs(nx,ny,cnt+1);
            if(change) map[ny+dy[i]][nx+dx[i]] = 1;
        }
    }

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

Measured memory_bytes: 12000
#include<stdio.h>
int main(void){
	int a[8][8];
	char v[8][8];
	int i,j;
	while(1){
	for(i = 0;i < 8;i++){
		for(j = 0;j < 8;j++){
			if(scanf(" %c",&v[i][j]) == EOF){
				return 0;
			}
			a[i][j] = v[i][j] - 48;
		}
		getchar();
	}
		getchar();
	for(i = 0;i < 8;i++){
		for(j = 0;j < 8;j++){
			if(a[i][j] == 1){
				if(a[i][j+1] == 1 && a[i+1][j] == 1 && a[i+1][j+1] == 1){
					printf("A\n");
					break;break;
				}
				else if(a[i+1][j] == 1 && a[i+2][j] == 1 && a[i+3][j] == 1){
					printf("B\n");
					break;break;
				}
				else if(a[i][j+1] == 1 && a[i][j+2] == 1 && a[i][j+3] == 1){
					printf("C\n");
					break;break;
				}
				/*else if(a[i+1][j] == 1 && a[i+1][j-1] == 1 && a[i+2][j-1] == 1){
					printf("D\n");
					break;break;
				}*/
				else if(a[i][j+1] == 1 && a[i+1][j+1] == 1 && a[i+1][j+2] == 1){
					printf("E\n");
					break;break;
				}
				else if(a[i+1][j] == 1 && a[i+1][j+1] == 1 && a[i+2][j+1] == 1){
					printf("F\n");
					break;break;
				}
				else if(a[i+1][j] == 1 && a[i+1][j-1] == 1 && a[i+2][j-1] == 1){
					printf("D\n");
					break;break;
				}
				else if(a[i][j+1] == 1 && a[i+1][j] == 1 && a[i+1][j-1] == 1){
					printf("G\n");
					break;break;
				}
			}
		}
	}
	}
	return 0;
}

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

int main() {
	// your code goes here
	string s;
	cin >> s;
	int flag = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'C') {
			flag = 1;
		}
		if (s[i] == 'F' && flag == 1) {
			cout << "Yes" << endl;
			return 0;
		}
		
	}
	cout << "No" << endl; 
	return 0;
}

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

m = 0

for i in range(N):
    a = input().rstrip().split(" ")
    x = float(a[0])
    u = a[1]    #jpy or btc
    
    if u == "JPY":
        m += x
    else:
        m += x * 380000.0

print(m)

Measured memory_bytes: 2940
N=int(input())
L=input().split()
L = [int(s) for s in L]
n=0
tem=0
# print(L)

for i in range(1000000000):

    for j in L:
        # print(j%2)
        tem+=j%2
    # print(tem)

    if tem!=0:
        break
    else:
        for k in range(len(L)):
            L[k]=L[k]/2
        n+=1
    # print(L)

# print("end")
print(n)




Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    long long H, N;
    long long result = 0;
    long long i = 2;
    cin >> H;
    N = H;
    if (N > 1) {
        N = N / 2;
        result++;
        for (; N > 1; i = i * 2) {
            N = N / 2;
            result = result + i;
        }
        cout << result + i << endl;
    }
    else {
        cout << 1 << endl;
    }
    
}   


Measured memory_bytes: 256
#include <iostream>

using namespace std;



int answer[10001];
int n;



void SearchAnswer(int x, int y, int z, int mIndex) {

	int ans = x * x + y * y + z * z + x * y + y * z + z * x;

	if (ans > n) return;


	answer[ans]++;

	if (mIndex <= 1) {
		SearchAnswer(x + 1, y, z, 1);
	}

	if (mIndex <= 2) {
		SearchAnswer(x, y + 1, z, 2);
	}

	if (mIndex <= 3) {
		SearchAnswer(x, y, z + 1, 3);
	}

}



int main()
{
	cin >> n;

	for (int i = 1; i <= 10000; i++){
		answer[i] = 0;
	}

	SearchAnswer(1, 1, 1, 1);


	for (int i = 1; i <= n; i++) {
		cout << answer[i] << endl;
	}
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int main() {
	// your code goes here
	fast
	int n;
	cin >> n;
	ll arr[n];
	for(auto &i : arr)cin >> i;
	unordered_map<int,int> m;
	for(int i=0;i<n;++i)m[arr[i]]++;
	ll cnt = 0;
	for(auto itr : m)
	{
		if(itr.second > itr.first)cnt+=itr.second-itr.first;
		else if(itr.first > itr.second)cnt+=itr.second;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 7980
def f(array):
    temp = 'abcdefghijklmnopqrstuvwxyz'
    ret = [0] * len(temp)
    cnt = 0
    for x in array:
        ret[temp.index(x)] += 1
        cnt += 1
        if cnt == 10:
            break
    return ret

N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

dic = {}
for i in range(N):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

cnt = 0
for v in dic.values():
    cnt += v * (v - 1) // 2

print(cnt)





Measured memory_bytes: 66904
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int MOD = 100000;

int main()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        vector<vector<vector<int> > > num(h+1, vector<vector<int> >(w+1, vector<int>(4, 0)));
        num[0][1][3] = num[1][0][1] = 1;
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                for(int k=0; k<3; ++k){
                    (num[i+1][j][1-k/2] += num[i][j][k+k/2]) %= MOD;
                    (num[i][j+1][2+(k+1)/2] += num[i][j][k+1]) %= MOD;
                }
            }
        }

        int ret = 0;
        for(int i=0; i<4; ++i)
            ret += num[h-1][w-1][i];
        ret %= MOD;
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int H, W;
char A[1000][1000];
bool f[1000][1000];

struct grid { int h, w, c; };

int main()
{
	int H, W, ans = 0;
	queue<grid> q;
	grid g;

	cin >> H >> W;
	rep(i, H) rep(j, W) cin >> A[i][j];

	rep(i, H) rep(j, W) {
		if (A[i][j] == '#') {
			f[i][j] = true;
			g.h = i, g.w = j, g.c = 0;
			q.push(g);
		}
	}

	while (!q.empty()) {
		grid current = q.front(); q.pop();
		grid next;
		int i = current.h;
		int j = current.w;
		int cost = current.c;

		ans = max(ans, cost);

		if (i - 1 >= 0 && !f[i - 1][j]) {
			f[i - 1][j] = true;
			next.h = i - 1, next.w = j, next.c = cost + 1;
			q.push(next);
		}

		if (i + 1 < H && !f[i + 1][j]) {
			f[i + 1][j] = true;
			next.h = i + 1, next.w = j, next.c = cost + 1;
			q.push(next);
		}

		if (j - 1 >= 0 && !f[i][j - 1]) {
			f[i][j - 1] = true;
			next.h = i, next.w = j - 1, next.c = cost + 1;
			q.push(next);
		}

		if (j + 1 < W && !f[i][j + 1]) {
			f[i][j + 1] = true;
			next.h = i, next.w = j + 1, next.c = cost + 1;
			q.push(next);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 14352
#include<stdio.h>
 int main(void){
 int r;
 int g;
 int b;
 scanf("%d",&r);
 scanf("%d",&g);
 scanf("%d",&b);
   int sum;
   sum=100*r+10*g+b;
  if (sum%4==0){
    printf("YES\n");
  }else{
    printf("NO\n");
  } 
 
 return 0;
 }

Measured memory_bytes: 128