akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($($args),*), ($($args),*));
    };
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

const M: usize = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();

    let n: usize = sc.cin();
    let xs = (0..n).map(|_| sc.cin::<u32>()).collect::<Vec<_>>();

    let mut ans = 0;
    for i in 0..n {
        ans += xs[i] - 1;
    }
    put!(ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/(b))
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const LL LL_INF = LL(999999999999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;
const int RUN_SOLVE = 1;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    for(int do_solve_time = 0;do_solve_time < RUN_SOLVE;do_solve_time++){
        void solve();
        if(DO_BENCHMARK){
            clock_t clock_start = clock();
            solve();
            clock_t clock_end = clock();
            const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
            cout << "\n------------------------------------\n" << time << "[ms]\n";
        }
        else solve();
    }
}

/*------------------------------↓ここからコード↓----------------------------------*/
void solve(){
    string S, T;
    cin >> S >> T;
    int min_count = INF;
    for(int i = 0;i < S.size()-T.size()+1;i++){
        int count = 0;
        for(int j = 0;j < T.size();j++){
            if(S.substr(i,T.size())[j] != T[j]){
                count++;
            }
        }
        min_count = min(min_count,count);
    }
    cout << min_count << endl;
}


Measured memory_bytes: 3648
#include <stdio.h>
int main()
{
	int a, b, c;
	while (1)
	{
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0) {
			return 0;
		}
		else if (a > b) {
			c = a;
			a = b;
			b = c;
		}
		printf("%d %d\n", a, b);
	}
	return 0;
}

Measured memory_bytes: 2716
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>

using namespace std;

using P = pair<int, int>;
using i64 = int64_t;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;

using mat2d_t = std::vector<std::vector<int64_t>>;
int64_t combination(int n, int r) {
    if (r*2 > n) r = n-r;
    i64 d1{1}, d2{1};
    for (int i = 1; i <= r; ++i ) {
      d1 *= (n-i+1);
      d2  *= i;
    }
    return d1/d2;
}

int main(int argc, char **argv) {
    i64 n;
    cin >> n;

    unordered_map<std::string, i64> mp;
    i64 mx{0};
    for (int i = 0; i< n; ++i) {
        std::string st;
        cin >> st;
        std::sort(st.begin(), st.end());
        auto it = mp.find(st);
        if (it != mp.end()) {
            ++(it->second);
            mx = max(mx,it->second);
        } else {
            mp.insert(make_pair(st, 1));
        }
    }
    //mat2d_t com;
    //combination(com, mx, 2);

    i64 ans{0};

    for (auto kv : mp) {
        if (kv.second == 1) continue;
        //ans += com[kv.second][2];
        ans += combination(kv.second, 2);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  string S; cin >> S;
  bool kaibun1 = true, kaibun2 = true, kaibun3 = true;

  ll i = 0, j = S.size()-1;
  while (i <= j) {
    kaibun1 = kaibun1 && S[i] == S[j];
    i++; j--;
  }

  i = 0;
  j = (S.size()-1)/2 - 1;
  while (i <= j) {
    kaibun2 = kaibun2 && S[i] == S[j];
    i++; j--;
  }

  i = (S.size()+3)/2 - 1;
  j = S.size() - 1;
  while (i <= j) {
    kaibun3 = kaibun3 && S[i] == S[j];
    i++; j--;
  }

  if (kaibun1 && kaibun2 && kaibun3) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  ll n, t, a, z = 0, ans;
  cin >> n >> t >> a;
  ans = t;
  rep(i, 1, n) {
    cin >> a;
    if(z + t > a) ans -= z + t - a;
    ans += t;
    z = a;
  }
  cout << ans << endl;
}


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

using namespace std;
using ll = long long;

int main()
{
  ll n = 0;
  ll x[4] = {0};

  cin >> n;

  for (ll i = 0; i < n; i++) {

    string temp;
    cin >> temp;

    if (temp == "AC") {

      x[0]++;

    } else if (temp == "WA") {

      x[1]++;

    } else if (temp == "TLE") {

      x[2]++;

    } else if (temp == "RE") {

      x[3]++;

    }
  }

  cout << "AC x " << x[0] << endl;
  cout << "WA x " << x[1] << endl;
  cout << "TLE x " << x[2] << endl;
  cout << "RE x " << x[3] << endl;
}

Measured memory_bytes: 3632
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b,c = LI()
    c -= a-b
    print(max(0,c))
    return

#B
def B():
    n = I()
    ans = 0
    for i in range(1,n+1):
        s = str(i)
        if len(s)%2:
            ans += 1
    print(ans)
    return

#C
def C():
    n = I()
    h = LI()
    h[0] -= 1
    for i in range(n-1):
        if h[i+1] < h[i]:
            print("No")
            return
        if h[i+1] > h[i]:
            h[i+1] -= 1
    print("Yes")
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 60144
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define maxn 300
LL f[maxn+5][maxn+5][maxn+5],h[maxn+5]; 
int main(){
	int n,k;scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",h+i);memset(f,0x1f,sizeof(f));
	h[n++]=0;
	for(int i=1;i<=k;i++)for(int j=0;j<n;j++)f[0][i][j]=h[j];
	f[0][0][0]=h[0];
	for(int i=1;i<n;i++){
		for(int j=0;j<=min(k,i);j++){
			for(int k=0;k<n;k++){
//				if(k==i)continue;
				f[i][j][i]=min(f[i][j][i],f[i-1][j][k]+max(0ll,h[i]-h[k]));
				f[i][j+1][k]=min(f[i][j+1][k],f[i-1][j][k]);
			}
		}
	}
	LL ans=**f[maxn+1];
	for(int j=0;j<n;j++)ans=min(ans,f[n-1][k][j]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 221952
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String T = sc.nextLine();
    String S = sc.nextLine();
    
    int count = 0;
    int store = S.length();
    
    for(int i = 0; i<=T.length()-S.length();i++){
      count = 0;
      for(int j = 0;j<S.length();j++){
      	if(S.charAt(j)!=T.charAt(i+j)){
        	count++;
      	}
      }
      if (store>=count) store = count; 
    }
    System.out.println(store);
  }
}
      

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i < N; ++i) {
    scanf("%d", &B[i]);
  }
  for (int i = 0; i < N; ++i) {
    scanf("%d", &C[i]);
  }
  sort(A.begin(), A.end());
  sort(C.begin(), C.end());
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    ll top = distance(A.begin(), lower_bound(A.begin(), A.end(), B[i]));
    ll bottom = distance(upper_bound(C.begin(), C.end(), B[i]), C.end());
    ans += top * bottom;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1408
n = int(input())
p = list(map(int,input().split()))

count = 0 
a = []

for i in range(n):
    if not p[i] == i + 1:
        a.append(i)
        count += 1

if len(a)==0:
    print("YES")
elif len(a)==2:
    if p[a[0]]==a[1]+1 and p[a[1]]==a[0]+1:
        print("YES")
    else:
        print("NO")
else:
    print("NO")
    

Measured memory_bytes: 3064
//大文字は65-90, 小文字は97-122
#include <iostream>
#include <string>
int main(){
  std::string s;
  bool a=true;
  int n=0;
  std::cin>>s;
  a=(s[0]=='A'?a:false);
  for(int i=2;i<s.size()-1;++i){
    if(s[i]=='C'){++n;}
    else{a=(s[i]>96&&s[i]<123?a:false);}
  }
  a=(s.back()>96&&s.back()<123?a:false);
  a=(s[1]>96&&s[1]<123?a:false);
  std::cout << (a&&n==1?"AC":"WA") << "\n";
}
  

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

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

using namespace std;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<vector<int>> G(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u].emplace_back(v);
	}

	double dp0[600]={};
	for(int u=n-2;u>=0;u--){
		for(int v:G[u]){
			dp0[u]+=dp0[v];
		}
		dp0[u]=dp0[u]/G[u].size()+1;
	}

	double ans=1e77;
	rep(i,n){
		int j=-1;
		for(int k:G[i]){ if(j==-1 || dp0[j]<dp0[k]) j=k; }

		double dp[600]={};
		for(int u=n-2;u>=0;u--){
			int deg=0;
			for(int v:G[u]) if(!(u==i && v==j)) {
				dp[u]+=dp[v];
				deg++;
			}
			dp[u]=dp[u]/deg+1;
		}
		ans=min(ans,dp[0]);
	}
	printf("%.15f\n",ans);

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	ll a,b,k;
	cin >> a >> b >> k;
	if(k<a && k<a+b) cout << a-k << ' ' << b;
	else if(k>=a&&k<a+b) cout << 0 << ' ' << b-(k-a);
	else cout << 0 << ' ' << 0;
	cout << "\n";
    return 0;
}



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

using namespace std;

int main(){
	int n,a;cin>>n;
	while(n--){
		cin>>a;
		if(a%2==0&&a%3!=0&&a%5!=0){cout<<"DENIED";return 0;}
	}
	cout<<"APPROVED";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

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

	vector <bool> primes(5000010, true);
	vector <ll> primeList;

	for(ll i = 2; i * i <= 5000000; i ++)
	{
		if(primes[i] == true)
		{
			for(ll j = i; i * j <= 5000000; j ++)
				primes[i * j] = false;
		}
	}

	for(ll i = 2; i <= 5000000; i ++)
	{
		if(primes[i] == true)
			primeList.push_back(i);
	}


	ll count = 0;
	ll ans = 0;
	for(ll prime : primeList)
	{
		if(prime * prime > n)
			break;
		ll count = 0;
		while(n % prime == 0)
		{
			n /= prime;
			count ++;
		}
		// debug(count);
		// cout << ceil((sqrt(8 * count + 1) - 1) / 2) << endl;
		ans += floor((sqrt(8 * count + 1) - 1) / 2);
	}

	if(n > 1)
		ans += 1;
	cout << ans << endl;
}

Measured memory_bytes: 8136
#include <bits/stdc++.h>
using namespace std;
int main(){
   int N;
   cin>>N;
   vector<vector<int>> vec(2,vector<int>(N));
   for(int i=0;i<2;i++){
       for(int k=0;k<N;k++)cin>>vec.at(i).at(k);
   }
   for(int k=0;k<2;k++){
       for(int i=1;i<N;i++)vec[k][i]+=vec[k][i-1];
   }
   vector<int>ans(N);
   ans[0]=vec[0][0]+vec[1][N-1];
   for(int i=1;i<N;i++){
       ans[i]=vec[0][i]+vec[1][N-1]-vec[1][i-1];
   }
   sort(ans.begin(),ans.end());
   cout<<ans[N-1]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int main(){
int n,k;
cin>>n>>k;
cout<<(n%k?1:0)<<endl;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (0<a and 0<c){
        c-=b;
        if (c<=0){
            cout << "Yes" << endl;
            break;
        }
        a-=d;
        if (a<=0){
            cout << "No" << endl;
            break;
        }

    }
}


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

int W, H;
bool Buildings[102][102] = {};
bool visible[102][102] = { false };

void visibilityDiffusion(int w, int h){
	if (w == 0 || h == 0 || w == W + 1 || h == H + 1) return;
	if (visible[w][h]) return;

	visible[w][h] = true;
	if (Buildings[w-1][h] == 0) visibilityDiffusion(w-1, h);
	if (Buildings[w+1][h] == 0) visibilityDiffusion(w+1, h);
	if (h % 2 == 1){
		// odd
		if (Buildings[w][h-1] == 0) visibilityDiffusion(w, h-1);
		if (Buildings[w][h+1] == 0) visibilityDiffusion(w, h+1);
		if (Buildings[w+1][h-1] == 0) visibilityDiffusion(w+1, h-1);
		if (Buildings[w+1][h+1] == 0) visibilityDiffusion(w+1, h+1);
	}
	else{
		// even
		if (Buildings[w-1][h-1] == 0) visibilityDiffusion(w-1, h-1);
		if (Buildings[w-1][h+1] == 0) visibilityDiffusion(w-1, h+1);
		if (Buildings[w][h-1] == 0) visibilityDiffusion(w, h-1);
		if (Buildings[w][h+1] == 0) visibilityDiffusion(w, h+1);
	}
}

int main(){
	cin >> W >> H;
	for (int i = 1; i <= H; i++){
		for (int j = 1; j <= W; j++){
			cin >> Buildings[j][i];
		}
	}

	// 建物がない場所のうち、外から見える部分を探索する
	for (int i = 1; i <= W; i++){
		if (Buildings[i][1] == 0) visibilityDiffusion(i, 1);
		if (Buildings[i][H] == 0) visibilityDiffusion(i, H);
	}
	for (int i = 1; i <= H; i++){
		if (Buildings[1][i] == 0) visibilityDiffusion(1, i);
		if (Buildings[W][i] == 0) visibilityDiffusion(W, i);
	}

	int ans = 0;
	int hole = 0;
	for (int i = 1; i <= H; i++){
		for (int j = 1; j <= W; j++){
			if (Buildings[j][i] == 1){
				ans += 6;
				if (Buildings[j + 1][i] == 1) ans -= 2;
				if (i % 2 == 1){
					// odd
					if (Buildings[j][i + 1] == 1) ans -= 2;
					if (Buildings[j + 1][i + 1] == 1) ans -= 2;
				}
				else{
					// even
					if (Buildings[j][i + 1] == 1) ans -= 2;
					if (Buildings[j - 1][i + 1] == 1) ans -= 2;
				}
			}
			else if (!visible[j][i]){
				hole += 6;
				if (Buildings[j + 1][i] == 0) hole -= 2;
				if (i % 2 == 1){
					// odd
					if (Buildings[j][i + 1] == 0) hole -= 2;
					if (Buildings[j + 1][i + 1] == 0) hole -= 2;
				}
				else{
					// even
					if (Buildings[j][i + 1] == 0) hole -= 2;
					if (Buildings[j - 1][i + 1] == 0) hole -= 2;
				}
			}
		}
	}

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

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

char field[101][101], a;
int H, W;

int dfs(int n, int m){
  if(m+1<=W){
  if(field[n][m+1]==a){
    field[n][m+1]='v';
    dfs(n, m+1);
  }}
  if(n+1<=H){
  if(field[n+1][m]==a){
    field[n+1][m]='v';
    dfs(n+1, m);
  }}
  if(m-1>=0){
  if(field[n][m-1]==a){
    field[n][m-1]='v';
    dfs(n, m-1);
  }}
  if(n-1>=0){
  if(field[n-1][m]==a){
    field[n-1][m]='v';
    dfs(n-1, m);
  }}
  
    return 1;
  
}

int main(void){
  int sum;
  while(cin >> H >> W){
  sum=0;
  if(H==0 && W==0)  break;
  string str;
  for(int i=0; i<H; i++){
    cin >> str;
    for(int j=0; j<W; j++){
      field[i][j]=str[j];
    }
  }
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(field[i][j]=='#'){
        a='#';
        sum+=dfs(i, j);
      } 
      else if(field[i][j]=='@'){
        a='@';
        sum+=dfs(i, j);
      }
      else if(field[i][j]=='*'){
        a='*';
        sum+=dfs(i, j);
      }
      else continue;
    }
  }
  cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 3436
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int S;
	long ANS;
	vector<int> A;
	cin >> S;
	A.push_back(S);

	for(long i=1;;i++)
	{
		if(A[i-1]%2==0)
		{
			A.push_back(A[i-1]/2);
			size_t Acount = count(A.begin(), A.end(), A[i]);
			if(Acount==2)
			{
				ANS=i+1;
				break;
			}
		}
		if(A[i-1]%2==1)
		{
			A.push_back(3*A[i-1]+1);
			size_t Acount = count(A.begin(), A.end(), A[i]);
			if(Acount==2)
			{
				ANS=i+1;
				break;
			}
		}
	}

	cout << ANS << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010,maxm=200010;
int n,m,head[maxn],cnt;
long long pos[maxn];
struct edge{
    int from,to,next,val;
}edges[maxm<<1];
bool vis[maxn];
inline void gaoci(){
    printf("No\n");exit(0);
}
inline void dfs(int p,long long ppos){
    pos[p]=ppos;vis[p]=true;
    for(register int i=head[p];i>=0;i=edges[i].next){
        if(vis[edges[i].to]&&(pos[edges[i].to]!=ppos+edges[i].val)) gaoci();
        if(!vis[edges[i].to]) dfs(edges[i].to,ppos+edges[i].val);
    }
}
int main(){
    scanf("%d%d",&n,&m);int x,y,z;
    memset(head,-1,sizeof(head));
    for(register int i=1;i<=m;i++){
        scanf("%d%d%d",&x,&y,&z);
        edges[cnt]=(edge){x,y,head[x],z};
        head[x]=cnt++;
        edges[cnt]=(edge){y,x,head[y],-z};
        head[y]=cnt++;
    }
    for(register int i=1;i<=n;i++) if(!vis[i]) dfs(i,0);
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 8832
n = int(input())
a = list(map(int, input().split()))
q = int(input())
count = [0]*(100001)
for i in range(n):
    count[a[i]] += 1
ans = sum(a)

for i in range(q):
    b, c = map(int, input().split())
    ans += count[b]*(c-b)
    count[c] += count[b]
    count[b] = 0
    print(ans)


Measured memory_bytes: 83888
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll _pow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; b >> i; i++) {
		if ((b >> i) & 1) ans *= a;
		a *= a;
	}
	return ans;
}
int di[4] = { -1, 1, 0, 0 };
int dj[4] = { 0, 0, -1, 1 };
char inp[405][405];
int chk[405][405];
ll black, white;
int Mi, Mj;
void dfs(int xi, int xj) {
	chk[xi][xj] = true;
	if (inp[xi][xj] == '.') white++;
	else black++;
	for (int k = 0; k < 4; k++) {
		int ni = xi + di[k], nj = xj + dj[k];
		if (0 <= ni && ni < Mi && 0 <= nj && nj < Mj) {
			if (!chk[ni][nj] && (inp[xi][xj] != inp[ni][nj])) {
				dfs(ni, nj);
			}
		}
	}
}

ll ans;
int main(void) {
	scanf("%d %d", &Mi, &Mj);
	for (int i = 0; i < Mi; i++) {
		for (int j = 0; j < Mj; j++) {
			scanf(" %c", &inp[i][j]);
		}
	}

	for (int i = 0; i < Mi; i++) {
		for (int j = 0; j < Mj; j++) {
			if (!chk[i][j]) {
				dfs(i, j);
				ans += black * white;
				black = white = 0;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

	

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c,d;
	
	cin>>a>>b>>c>>d;
	
	while(a>0&&c>0){
    c-=b;
    if(c<=0){
      cout<<"Yes";
    	break;}
    a-=d;
    if(a<=0){
      cout<<"No";
    	break;} 
    }
 
	return 0;
}

Measured memory_bytes: 3620
//Created Time:2019/12/9 8:57:49
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define mod 1000000007
#define ll long long

using namespace std;

ll f[100];

void init();
void work(ll, ll);
int calc(ll, ll, ll, ll);
ll read();

int main(){
	init(); int t; cin >> t;
	while(t--){
		ll x = read(), y = read();
		if(x > y) swap(x, y); work(x, y);
	}
	return 0;
}

void init(){
	f[1] = 1;
	for(int i = 2; i <= 88; ++i)
		f[i] = f[i - 1] + f[i - 2];
	return ;
}

int calc(ll x, ll y, ll a, ll b){
	int ans = ((y - b) / a + 1) % mod;
	if(b <= x) (ans += ((x - b) / a + 1) % mod) %= mod;
	return ans;
}

void work(ll x, ll y){
	if(x == 1){
		printf("%d %d\n", 1, y % mod);
		return ;
	}
	if(x == 2 && y == 2){
		puts("1 4");
		return ;
	}
	int pos = upper_bound(f + 1, f + 89, x) - f - 1;
	if(f[pos + 1] > y) --pos; printf("%d ", pos - 1);
	ll a = f[pos], b = f[pos + 1];
	int ans = calc(x, y, a, b);
	for(int i = 2; i < pos; ++i){
		ll na = a + f[pos - i] * f[i], nb = b + f[pos - i + 1] * f[i];
		if(na < a || nb < b || na > x || nb > y) continue;
		(ans += calc(x, y, na, nb)) %= mod;
	}
	printf("%d\n", ans);
	return ;
}

ll read(){
	ll x = 0; char ch = getchar();
	for(; !isdigit(ch); ch = getchar());
	for(; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
	return x;
}

Measured memory_bytes: 3968
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#import fractions
#S=input()
#import math
#lis=list(map(int,input().split()))

n=int(input())
sp={}
for i in range(n):
    li=input().split()
    li.append(i+1)
    li[1]=int(li[1])
    if li[0] not in sp:
        sp[li[0]]=[li]
    else:
        sp[li[0]].append(li)
        sp[li[0]].sort(reverse=True)
items_sorted = sorted(sp.items())
#print(items_sorted)
for i in range(len(items_sorted)):
    for j in range(len(items_sorted[i][1])):
        print(items_sorted[i][1][j][2])


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> abs_diff(const vector<int> &xs, const vector<int> &ys);
double minkov(const vector<int> &difs, int p);

int main(){
    int n;
    cin >> n;
    vector<int> xs(n, 0), ys(n, 0);
    for(auto &x : xs) cin >> x;
    for(auto &y : ys) cin >> y;
    vector<int> difs = abs_diff(xs, ys);
    cout << fixed << setprecision(6);
    cout << minkov(difs, 1) << endl;
    cout << minkov(difs, 2) << endl;
    cout << minkov(difs, 3) << endl;
    cout << *max_element(difs.begin(), difs.end()) << endl;

}

vector<int> abs_diff(const vector<int> &xs, const vector<int> &ys){
    vector<int> difs(xs.size(), 0);
    for(size_t i = 0; i != xs.size(); ++i) difs[i] = abs(xs[i] - ys[i]);
    return difs;
}


double minkov(const vector<int> &difs, int p){
    double sum = 0;
    for(auto dif : difs) sum += pow(dif, p);
    return pow(sum, 1.0 / p);
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int sheep, wolf;
  cin >> sheep >> wolf;

  if(sheep > wolf) cout << "safe" << endl;
  else cout << "unsafe" << endl;

  return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <cmath>

class UnionFind {
	private:
		std::vector<int> parents;
		std::vector<int> n_group;
	public:
		UnionFind(int n) {
			parents.resize(n);
			n_group.resize(n);
			for(int i = 0; i < n; ++i) {
				parents[i] = i;
				n_group[i] = 1;
			}
		}
		int find(int v) {
			if(parents[v] == v) return v;
			else return parents[v] = find(parents[v]);
		}
		void unite(int u, int v) {
			int ru = find(u);
			int rv = find(v);
			if(ru == rv) return;
			else {
				parents[ru] = rv;
				n_group[rv] += n_group[ru];
			}
			return;
		}
		int size(int v) {
			return n_group[find(v)];
		}
};

int main(void) {
	// in
	int n, m;
	std::cin >> n >> m;
	std::vector<int> a(m), b(m);
	for(int j = 0; j < m; ++j) {
		std::cin >> a[j] >> b[j];
		--a[j];
		--b[j];
	}

	// union find
	UnionFind uf(n);
	std::vector<long long> fubensa(m);
	fubensa[m-1] = (long long)n * (long long)(n-1) / 2;
	for(int j = m-1; j > 0; --j) {
		if(uf.find(a[j]) == uf.find(b[j])) fubensa[j-1] = fubensa[j];
		else fubensa[j-1] = fubensa[j] - uf.size(a[j]) * uf.size(b[j]);
		uf.unite(a[j], b[j]);
		//for(int i = 0; i < n; ++i) {
		//	std::cout << uf.size(i);
		//}
		//std::cout << std::endl;
	}
	
	for(int j = 0; j < m; ++j) std::cout << fubensa[j] << std::endl;

	return 0;
}


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

int main(int argc, char** argv) {
	uint64_t r, x2000, D, xi;
	cin >> r >> D >> x2000;
	xi = x2000;
	for (int i = 1; i <= 10; ++i) {
		xi = r * xi - D;
		cout << xi << endl; 
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int n;
    int num;
    int max = 0,min = pow(10,10);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> num;
        if(max < num)max = num;
        if(min > num)min = num;
    }
    cout << max - min;
}


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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  for (int i = min(a, b); i <= max(a, b); ++i) {
    if (abs(a - i) == abs(b - i)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}



Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto nm = readints;
    int n = nm[0], m = nm[1];

    auto uf = new UnionFind(n);
    for (int i = 0; i < m; i++) {
        auto xyz = readints;
        int x = xyz[0], y = xyz[1];
        uf.unite(x, y);
    }

    bool[int] d;
    for (int i = 1; i <= n; i++) {
        d[uf.root(i)] = true;
    }

    auto ans = d.keys.length;
    writeln(ans);
}

class UnionFind {
    private int[] _data;
    private int[] _nexts; // 次の要素。なければ -1
    private int[] _tails; // 末尾の要素

    this(int n) {
        _data  = new int[](n + 1);
        _nexts = new int[](n + 1);
        _tails = new int[](n + 1);

        _data[] = -1;
        _nexts[] = -1;
        for (int i = 0; i < _tails.length; i++)
            _tails[i] = i;
    }

    int root(int a) {
        if (_data[a] < 0) return a;
        return _data[a] = root(_data[a]);
    }

    bool unite(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra != rb) {
            if (_data[rb] < _data[ra]) swap(ra, rb);
            _data[ra] += _data[rb]; // ra に rb を繋げる
            _data[rb] = ra;
            // ra の末尾の後ろに rb を繋げる
            _nexts[_tails[ra]] = rb;
            // ra の末尾が rb の末尾になる
            _tails[ra] = _tails[rb];
        }
        return ra != rb;
    }

    bool isSame(int a, int b) {
        return root(a) == root(b);
    }

    /// a が属する集合のサイズ
    int groupSize(int a) {
        return -_data[root(a)];
    }

    /// a が属する集合の要素全て
    void doEach(int a, void delegate(int) fn) {
        auto node = root(a);
        while (node != -1) {
            fn(node);
            node = _nexts[node];
        }
    }
}


Measured memory_bytes: 7676
n, m = map(int, input().split())
a = []
for i in range(n):
    i,j = (map(int, input().split()))
    a += [[i,j]]
a = sorted(a)
count = 0
value = 0
for (i,j) in a:
    if count + j >= m:
        value += (m - count) * i
        break
    else:
        value += i * j
        count += j
print(value)

Measured memory_bytes: 20764
#include<stdio.h>
#define N 100000

int Parent(int i){
  return i/2;
}

int Left(int i){
  return 2*i;
}

int Right(int i){
  return 2*i+1;
}

int main(void){
  int i,n,T[N];

  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d",&T[i]);
  }
 
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,T[i]);
    if(T[Parent(i)]!=NULL)printf("parent key = %d, ",T[Parent(i)]);
    if(T[Left(i)]!=NULL)printf("left key = %d, ",T[Left(i)]);
    if(T[Right(i)]!=NULL)printf("right key = %d, ",T[Right(i)]);
    printf("\n");
  }
  
  return 0;

}

Measured memory_bytes: 608
#include<iostream>

using namespace std;
int main()
{  
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    long long a;
    long long ans=0;
    cin>>a;
	for (long long i = 1;i<=a;i++){
		if((i%3 != 0)and(i%5 !=0)){
			ans += i;

		}
	}
	cout<<ans;
	
	
    
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
////////////////
void solve(){
  inl(N);
  ll ans = N + 1;
  for(ll i = 1; i * i <= N; i++){
    if(N % i) continue;
    amin(ans , i + N / i);
  }
  out(ans - 2);
}


Measured memory_bytes: 256
#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>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    vector<int> A;

    void input() {
        cin >> N;
        A.resize(N);
        rep(i, 0, N) {
            cin >> A[i];
        }

    }

    void solve() {
        input();
        int SUM = accumulate(all(A),0);
        int key = -1;
        int val = INF;

        for(int i = 0; i < N; ++i){
            int tmp = abs(A[i] * N - SUM);
            if(val > tmp){
                val = tmp;
                key = i;
            }
        }

        cout << key << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
A,B = map(int,input().split())
if (A == 1):
  if (B == 1):
    print('Draw')
  else:
    print('Alice')
else:
  if (B == 1):
    print('Bob')
  elif (A == B):
    print('Draw')
  elif (A > B):
    print('Alice')
  else:
    print('Bob')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll get(ll x) {
	return x*x*x;
}
int main() {
	ll n,k,ans=0;
	cin>>n>>k;
	if (k&1) {
		cout<<get(n/k);
	}
	else {
		cout<<get(n/k)+get(2*n/k-n/k);
	}
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int ans =1;
  
  while(n>0){
  	if(ans > k){
    	ans += k;
 	}else{
   	 	ans *=2;
  	}
    n--;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define mod 998244353
#define inv2 499122177
#define M 1000005
int n,I[M],P[M];
int read(){
	char c=getchar();int ans=0;
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') ans=ans*10+c-'0',c=getchar();
	return ans;
}
void Write(int x){
	if (x<10) putchar(x^48);
	else Write(x/10),putchar((x%10)^48);
	return;
}
int invs(int x){return x==1?1:(mod-mod/x+0ll)*invs(mod%x)%mod;}
int add(int u,int v){return (u+=v)>=mod?u-mod:u;}
int sub(int u,int v){return (u-=v)<0?u+mod:u;}
void FWT(int *A,int len,int flag){
	int tmp;
	for (register int l=1;l<len;l<<=1)
		for (register int i=0;i<len;i+=(l<<1))
			for (register int j=0;j<l;j++)
				tmp=A[i|j|l],A[i|j|l]=sub(A[i|j],tmp),A[i|j]=add(A[i|j],tmp);
	if (flag==-1)
		for (register int i=0,tmp=invs(len);i<len;i++) A[i]=(A[i]+0ll)*tmp%mod;
	return;
}
int main(){
	n=read();
	for (register int i=0;i<(1<<n);i++) P[i]=read(),P[1<<n]+=P[i];
	P[1<<n]=invs(P[1<<n]);
	for (register int i=0;i<(1<<n);i++) P[i]=P[i]*(P[1<<n]+0ll)%mod,I[i]=mod-1;I[0]=(1<<n)-1;
	P[1<<n]=0;P[0]=sub(P[0],1),FWT(P,1<<n,1),FWT(I,1<<n,1);
	for (register int i=1;i<(1<<n);i++) P[i]=(I[i]+0ll)*invs(P[i])%mod;P[0]=0;FWT(P,1<<n,-1);
	for (register int i=0,tmp=sub(0,*P);i<(1<<n);i++) Write(add(P[i],tmp)),putchar('\n');
	return 0;
}


Measured memory_bytes: 7936
a,b,c=map(int,input().split())

d=[]
i=1
while 1:
  if (a*i)%b==c:
    print("YES")
    break
  if d.count((a*i)%b):
    print("NO")
    break
  else:
    d.append((a*i)%b)
  i=i+1



Measured memory_bytes: 2940
int main() {
  int n;
  if(scanf("%d",&n) == 0)
    return 0;
  if(n>10000 || n<=0) {
    printf("You have to enter positive number less than 10000\n");
    return 0;
  }
  if (n%1000 == 0)
    printf("%d",0);
  else if (n!=10000)
    printf("%d",1000-n%1000);
  else
    printf("%d",0);
  return 0;
}

Measured memory_bytes: 1684
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    long long ans = 1;
    long long N,M;
    cin >> N;
    cin >> M;
    
    if ( abs(N-M) > 1 ) {
        cout << 0 << endl;
        return 0;
    }
    
    long long l,s;
    
    l = max(N,M);
    s = min(N,M);
    
    bool is_equal = (l == s);
    
    while( l ) {
        ans *= l;
        ans %= (1000000007);
        l--;
    }
    while( s ) {
        ans *= s;
        ans %= (1000000007);
        s--;
    }
    
    if ( is_equal ) {
        ans *= 2;
        ans %= (1000000007);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, M = MAP()

if N==M:
	print(1)
	sys.exit()

X = M//N+1
for i in range(X, -1, -1):
	if M % i == 0:
		print(i)
		sys.exit()
print(0)

Measured memory_bytes: 40044
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int n,m;
	std::cin >> n >> m;
	std::vector<std::string> a(n);
	std::vector<std::string> b(m);
	rep(i,n) std::cin >> a[i];
	rep(i,m) std::cin >> b[i];
	if(m>n) {
		print("No");
		return 0;
	}
	for(int ix = 0; ix<=n-m; ix++) {
		for(int iy = 0; iy<=n-m; iy++) {
			for(int x = 0; x<m; x++) {
				for(int y = 0; y<m; y++) {
					if(b[x][y]!=a[ix+x][iy+y]) {
						goto exit;
					}
				}
			}
			print("Yes");
			return 0;
exit:;
		}
	}
	print("No");

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;



int32_t main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	// cout.tie(0);
	ios::sync_with_stdio(!cin.tie(NULL));

#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________


	int n; cin >> n;
	string s1;
	cout << 0 << endl;
	cin >> s1;
	if (s1 == "Vacant")
		return 0;
	int l = 0;
	int r = n;
	string s2;
	while (true)
	{
		int m = (l + r) / 2;
		cout << m << endl;
		cin >> s2;
		if (s2 == "Vacant")
		{
			return 0;
		}
		if (((m - l) % 2 == 1 && s2 == s1) || ((m - l) % 2 == 0 && s1 != s2))
		{
			r = m;
		}
		else
		{
			l = m;
			s1 = s2 ;
		}
	}
	assert(false);


	return 0;
}



Measured memory_bytes: 3824
inf = 1 << 60
A,B,Q = map(int,input().split())
s = []
t = []
x = []
s.append(-inf*2)
s.append(-inf)
t.append(-inf*2)
t.append(-inf)
for i in range(A):
    s.append(int(input()))
for i in range(B):
    t.append(int(input()))
for i in range(Q):
    x.append(int(input()))
s.append(inf)
s.append(inf*2)
t.append(inf)
t.append(inf*2)

def search(lst, target):
    min1 = 0
    max1 = len(lst)
    while max1 - min1 > 1:
        mid1 = (min1 + max1) // 2
        if lst[mid1] <= target:
            min1 = mid1
        else:
            max1 = mid1
    return min1

def solve(x):
    chk = [0] * 8
    s1 = search(s, x)

    chk[0] = abs(s[s1] - x)
    chk[1] = abs(s[s1] - x)
    chk[2] = abs(s[s1+1] - x)
    chk[3] = abs(s[s1+1] - x)

    t1 = search(t, s[s1])
    t2 = search(t, s[s1+1])
    chk[0] += abs(t[t1] - s[s1])
    chk[1] += abs(t[t1+1] - s[s1])
    chk[2] += abs(t[t2] - s[s1+1])
    chk[3] += abs(t[t2+1] - s[s1+1])

    t1 = search(t, x)

    chk[4] = abs(t[t1] - x)
    chk[5] = abs(t[t1] - x)
    chk[6] = abs(t[t1+1] - x)
    chk[7] = abs(t[t1+1] - x)

    s1 = search(s, t[t1])
    s2 = search(s, t[t1+1])
    chk[4] += abs(s[s1] - t[t1])
    chk[5] += abs(s[s1+1] - t[t1])
    chk[6] += abs(s[s2] - t[t1+1])
    chk[7] += abs(s[s2+1] - t[t1+1])

    return min(chk)

for xi in x:
    ans = solve(xi)
    print(ans)


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

int main() {
	string s;
	cin >> s;
	if(s=="RRR"){
		cout << 3 << endl;
	}else if(s=="SSS"){
		cout << 0 << endl;
	}else if(s=="RRS" || s=="SRR"){
		cout << 2 << endl;
	}else{
		cout << 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#!/mnt/c/Users/moiki/bash/env/bin/python
D,G = map(int, input().split())
points = [ [int(j) for j in input().split()] for _ in range(D)]
points = [ [x[0], x[1], 100*e*x[0]] for e,x in enumerate(points, 1)]


ans = float("inf")
for i in range(1<<D): # for complete bonus bit set 
    lg = G
    cnt = 0
    for d in range(D):
        if i & (1<<d) != 0:
            lg -= points[d][1] # complete bonus
            lg -= (100*(d+1))*points[d][0] # normal points
            cnt += points[d][0]
            if lg <= 0:
                break
    if lg <= 0:
        ans = min(ans, cnt)
        continue
    
    # other points
    for d in range(D-1, -1, -1):
        if i & (1<<d) != 0: continue

        if lg <= points[d][2]:
            quot = (lg+(100*(d+1)-1)) // (100*(d+1))
            lg -= 100*(d+1)*quot
            cnt += quot;  break
        else:
            cnt += points[d][0]
            lg -= 100*(d+1)*points[d][0]
            cnt += points[d][0]
    if lg <= 0:
        ans = min(ans, cnt)
        continue
print(ans)

        

        



            



Measured memory_bytes: 41072
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val aList = listOf(1, 3, 5, 7, 8, 10, 12)
    val bList = listOf(4, 6, 9, 11)

    val nums = listOfInt()

    if ((aList.contains(nums[0]) && aList.contains(nums[1])) || 
        (bList.contains(nums[0]) && bList.contains(nums[1]))) {
        println("Yes")
    } else {
        println("No")
    }
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 35848