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

using namespace std;

int main()
{ 
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<char>> v(h,vector<char>(w));
    map<int,int> rowc;
    map<int,int> colc;
    int total = 0;
    for(int i = 0;i<h;i++)
    {
        for(int j = 0;j<w;j++)
        {
            cin>>v[i][j];
            if(v[i][j] == '#')
            {
                rowc[i]++;
                colc[j]++;
                total++;
            }
        }
    }

    int ways = 0;


    //Let's fucking do Masking

    for(int mask1 = 0;mask1 < (1<<h) ; mask1++)
    {
        long long subsum = 0;
        set<int> s;
        for(int i=0;i<h;i++)
        {
            if(mask1 & (1<<i))
            {
                subsum += rowc[i];
                s.insert(i);
            }
        }
        for(int mask2 = 0;mask2 < (1<<w) ; mask2++)
        {
            long long sum2 = 0;
           for(int i=0;i<w;i++)
          {
            if(mask2 & (1<<i))
            {
                int tc = 0;
                for(auto it = s.begin();it!=s.end();++it)
                {
                    int index = *it;
                    if(v[index][i] == '#')
                    {
                        tc++;
                    }
                }

                sum2 += colc[i] - tc;
            }
          }

         if(subsum + sum2 == (total - k))
         {
            ways++;
         }

        }
       
    }

    cout<<ways;

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int x[3000],y[3000];
	int i =0;
	int swap;
	for(i=0;i<100000;++i){
		scanf("%d%d",&x[i],&y[i]);
		if(x[i]==0&&y[i]==0) break;
		if(x[i]>y[i]){
			swap=x[i];
			x[i]=y[i];
			y[i]=swap;
		}
	}
	for(int j=0;j<i;++j) cout<<x[j]<<" "<<y[j]<<endl;
return 0;
}

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

int main() {
  int N, K, S = 0;
  cin >> N >> K;
  vector<int> p(N);
  for(int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  for(int i = 0; i < K; i++) {
    S += p.at(i);
  }
  cout << S << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define pi 3.14159
using namespace std;

struct ca
{
  int idx,st,et,aidx;
};

int prime[1000001]={};

int power(int x, unsigned int y, int p)  
{  
    int res = 1;     
  
    x = x % p; 
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
         
        if (y & 1)  
            res = (res*x) % p;  
  
        
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  

void pr()
{
  prime[1]=0;

 for(int i=2;i*i<1000001;i++)
  if(prime[i]==0)
  for(int j=i*i;j<1000001;j+=i)
  prime[j]=1;

}

int countSetBits( int n) 
{ 
     int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 
  
bool cmp1(ca c1,ca c2)
{
  if(c1.st<c2.st)
   return true;

  if(c1.st==c2.st && c1.idx<c2.idx)
   return true;

  return false;
}

bool cmp2(ca c1,ca c2)
{
  
  if(c1.idx<c2.idx)
  return true;
  return false;
}








int main()
{

  ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   //pr();
  int t;
  // cin>>t;
   t=1;
  int id=1;

  while(t--)
{
     int n;
      cin>>n;

   double d= 2*n*(3.14159);

     cout<<fixed<<setprecision(2)<<d;
   
}



return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


vector<pair<int,string>> v[1000000];
map<string,int> mp;

int main(){
  int N;
  int M=0;
  cin >> N;
  rep(i,N){
    string s;
    cin >> s;
    mp[s]++;
    if(mp[s] > M) M = mp[s];
  }

  for(auto it = mp.begin(); it != mp.end(); it++){
    if(it->second == M){
      cout << it->first << endl;
    }
  }

  
  
  return 0;
}




Measured memory_bytes: 48640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		S = new StringBuffer(S).reverse().toString();
		String[] keys = {"dream", "dreamer", "erase", "eraser"};
		boolean can = true;
		for (int i=0; i<S.length();) {
			boolean can2 = false;
			for (int j=0; j<4; j++) {
				String key = keys[j];
				key = new StringBuffer(key).reverse().toString();
				if ( i+key.length() > S.length() ) continue;
				if ( (S.substring(i, i+key.length())).equals(key) ){
					can2 = true;
					i+=key.length();
				}
			}
			if ( !can2 ) {
				can = false;
				break;
			}
		}
		if (can) System.out.println("YES");
		else System.out.println("NO");
	}
}


Measured memory_bytes: 35988
n = int(input())
a = list(map(int, input().split()))
res = 0
new_color = max(a) + 1
cnt = 1
for i in range(len(a)-1):
    next_slime = a[i + 1]
    if next_slime == a[i]:
        cnt += 1
    else:
        res += (cnt // 2)
        cnt = 1
if cnt > 0:
    res += (cnt // 2)
print(res)


Measured memory_bytes: 3060
//written by NewbieChd
#include <cstdio>
#include <cctype>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 100003;

int main() {
    int r = read(), d = read(), x = read(), i;
    for (i = 1; i <= 10; ++i)
        printf("%d\n", x = x * r - d);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

int main() {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin>>x1>>y1>>x2>>y2;

    x3=y1-y2+x2;
    y3=x2-x1+y2;
    x4=y1-y2+x1;
    y4=x2-x1+y1;
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    string x;
    cin >> x;
    int ans = x.size(), cnt = 0;
    REP(i,x.size()){
        if(x[i] == 'S') cnt++;
        else if(cnt > 0){
            cnt--;
            ans -= 2;
        }
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll h,w; cin>>h>>w;
    char s[h][w];
    rep(i,h)rep(j,w) cin>>s[i][j];

    ll di[]={1,0,-1,0},dj[]={0,1,0,-1};
    bool ok=true;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.') continue;
            bool ok2=false;
            rep(k,4){
                ll ni=i+di[k],nj=j+dj[k];
                if(ni<0||h<=ni||nj<0||w<=nj) continue;
                if(s[i][j]=='#' && s[ni][nj]=='#') ok2=true;
            }
            if(!ok2){
                ok=false;
                break;
            }
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3508
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    char s[100050];
    int a[100050]={0};
    int n,q;
    cin >> n >> q >>s;
    for(int i=1;i<n;i++)
    {
        if(s[i]=='C'&&s[i-1]=='A')
            a[i]=a[i-1]+1;
        else
            a[i]=a[i-1];
    }
    while(q--)
    {
        int num1,num2;
        cin >> num1 >>num2 ;
        cout << a[num2-1]-a[num1-1] << endl;
    }
    return 0;
}


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

LL p(int x){
	return 1ll*x*x*x*x*x;
}
int main(){
	LL n;
	cin>>n;
	for(int i=-200;i<=200;i++)
		for(int j=-200;j<=200;j++){
			if(p(i)-p(j)==n){
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
}

Measured memory_bytes: 3584
def resolve():
    n = int(input())
    prev = None
 
    arr = map(int, input().split(" "))
 
    for a in arr:
        if prev is not None:
            if a - prev > 0:
                a -= 1
            elif a - prev < 0:
                print("No")
                return
        else:
            a -= 1
 
        prev = max(a, 1)
 
    print("Yes")
 
resolve()

Measured memory_bytes: 11248
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n,res;
  cin >> n;
  if(n>=100000)
    res=max(n-999999,0)+90000+900+9;
  else if(n>=1000)
    res=max(n-9999,0)+900+9;
  else if(n>=10)
    res=max(n-99,0)+9;
  else
    res=n;
  cout << res << endl;
  return 0;
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

#define b first
#define a second

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, sum = 0;
	vector<pair<int,int>> in;
	
	cin>>N;
	
	in.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].a>>in[i].b;
	}
	
	sort(in.begin(), in.end());
	
	for(int i = 0; i < N; i++){
		sum += in[i].a;
		if(in[i].b < sum){
			cout<<"No"<<endl;
			return 0;
		}
	}
	
	cout<<"Yes"<<endl;
	
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <iostream>
#include <set>
#include <string>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
    int a,b,c,d,e,k;
    int sz[5];
    for(int i=0;i<5;i++)
        cin>>sz[i];
    cin>>k;
    int cnt=1;
    for(int i=0;i<4;i++)
    {
        for(int j=i+1;j<5;j++)
        {
            if(abs(sz[i]-sz[j])>k)
            {
                cnt=0;
                break;
            }
        }
    }
    if(cnt)
    {
        cout<<"Yay!"<<endl;
    }
    else
        cout<<":("<<endl;
    return 0;
}


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

int main(){
    int N, K;
    std::cin >> N >> K;
    int keta = 0;
    while(N > 0){
        keta++;
        N /= K;
    }
    std::cout << keta << std::endl;
    return 0;
}


Measured memory_bytes: 256
# 自力では解けなかった(2020.7.6)

alpha = ['Z']
alpha.extend([chr(ord('a') + i) for i in range(26)])
N = int(input())
q = N
ans = ''
while True:
    if q <= 26:
        ans += str(alpha[q])
        break
    else:
        q, mod = divmod(q, 26)
        if mod == 0:
            q -= 1
            mod = 26
        ans += str(alpha[mod])

print(ans[::-1])

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

/*
#define bool int
#define false 0
#define true 1
*/

#define INF INT_MAX/3

#define MAX_N 1000

int n,m;
int board[1111][1111];
bool is_prime[1111111];

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

P mem[1111][1111];

P dfs(int x,int y){
	if(mem[x][y]!=P(-1,-1))return mem[x][y];
	P res=P(0,0);
	repl(xx,x-1,x+2){
		if(xx>=0&&xx<1111&&y+1>=0&&y+1<1111&&board[xx][y+1]!=0&&board[xx][y+1]<=m)maxch(res,dfs(xx,y+1));
	}
	if(is_prime[board[x][y]]){
		res.fi++;
		if(res.se==0)res.se=board[x][y];
	}
	return mem[x][y]=res;
}

int main(){
	cin.sync_with_stdio(false);
	memset(is_prime,1,sizeof(is_prime));
	is_prime[0]=is_prime[1]=false;
	rep(i,1111111){
		if(is_prime[i]){
			for(int j=i*2;j<1111111;j+=i)is_prime[j]=false;
		}
	}
	int num=1;
	int x=1111/2,y=1111/2;
	int len=1,state=0;
	while(1){
		rep(i,2){
			rep(j,len){
				board[x][y]=num++;
				x+=dx[state];y+=dy[state];
			}
			state=(state+1)%4;
		}
		if(num>1000000)break;
		len++;
	}
	while(1){
		cin>>m>>n;
		if(n==0)break;
		int sx,sy;
		rep(i,1111)rep(j,1111){
			if(board[i][j]==n){
				sx=i;sy=j;
			}
		}
		rep(i,1111)rep(j,1111)mem[i][j]=P(-1,-1);
		P res=dfs(sx,sy);
		cout<<res.fi<<" "<<res.se<<endl;
	}
	return 0;
}

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

int main() {
	// your code goes here
	int n, m=0, l=1000, k;
	cin >> n;

	for(int i=0; i<n; i++){
		cin >> k;
		m = max(m, k);
		l = min(l, k);
	}
	cout << m - l << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0,ans = 1;
  cin >> N;
  vector<char>A(N);
  rep(i,N){
    cin >> A[i];
  }
  rep(i,N-1){
    if(A[i] != A[i+1]){
      ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3692
import heapq
N,M = map(int,input().split())
INF = float("inf")
edge = [[] for _ in range(N)]
#print(load)
#dis = [[] for _ in range(N)]
List = [] #0は未使用、1は使用
for i in range(M):
  a,b,c = map(int,input().split())
  a-=1;b-=1
  edge[a].append([c,b,i])
  edge[b].append([c,a,i])
  List.append([c,a,b,i])

def dijkstra_heap(s):
  d = [INF for _ in range(N)]
  used = [True for _ in range(N)]
  d[s] = 0
  used[s] = False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while len(edgelist):
    minedge = heapq.heappop(edgelist)
    if not used[minedge[1]]: #すでに探索済みの場合にはスキップ
      continue
    v = minedge[1]
    d[v] = minedge[0]
    #L.add(minedge[2]) #この道を使用したと記録
    used[v] = False
    for e in edge[v]:
      if used[e[1]]:
        heapq.heappush(edgelist,[e[0]+d[v],e[1],e[2]])
  return d

L = set([])
for i in range(N):
  dist = dijkstra_heap(i)
  for c, s, g, ID in List: #道のリストの一つ一つの点を見て、それが最短距離で使われているか確認
    if dist[s] + c == dist[g]:
      L.add(ID)
ans = M -len(L)
print(ans)

Measured memory_bytes: 53596
# B - Similar Arrays
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
N = ni()
A = nl()

odd = 0
for a in A:
    if a%2 == 1:
        if odd == 0:
            odd = 1
            continue
        odd *= 1
    elif a%2 == 0:
        if odd == 0:
            odd = 2
            continue
        odd *= 2
print(3**N-odd)


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

ll N, ans = 0;

void count(ll x, int b3, int b5, int b7);

int main(){
	cin >> N;
	count(0, 0, 0, 0);
	cout << ans << endl;
	return 0;
}

void count(ll x, int b3, int b5, int b7){
	if(x > N){
		return;
	}
	if(b3+b5+b7 == 3){
		ans++;
	}
	count(10*x+3, 1, b5, b7);
	count(10*x+5, b3, 1, b7);
	count(10*x+7, b3, b5, 1);
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Set<Integer> set = new HashSet<>();
		String a = sc.next();
		String b = sc.next();
		int c = 1;
		if(a.length()+1 !=b.length()) c=0;
		for(int i =0; i<a.length();i++) {
			if(!(a.charAt(i)==b.charAt(i))) c =0;
		}
		if(c==1)System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 35648
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let t: usize = sc.read();
    for _ in 0..t {
        let n: usize = sc.read();
        let a: Vec<u64> = sc.vec(n);
        let s = sc.chars().into_iter().map(|c| c == '0').collect::<Vec<_>>();
        if solve(a, s) {
            println!("0");
        } else {
            println!("1");
        }
    }
}

fn solve(a: Vec<u64>, s: Vec<bool>) -> bool {
    let n = a.len();

    let mut bases = vec![];
    for i in (0..n).rev() {
        let mut cur = a[i];
        for &s in bases.iter() {
            if cur ^ s < cur {
                cur ^= s;
            }
        }
        if cur != 0 {
            if !s[i] {
                return false;
            }

            bases.push(cur);
        }
    }
    true
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

long long n,a[100005],d[2],br;

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

    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);

    int cnt=1;
    for(int i=n-2;i>=0;i--)
    {
        if(br==2)
            break;

        cnt++;
        if(a[i]==a[i+1]&&cnt==2)
        {
            d[br]=a[i];
            br++;
            cnt=0;
        }
        else if(a[i]!=a[i+1])
            cnt=1;
    }
    cout<<d[0]*d[1]<<endl;

    return 0;
}


Measured memory_bytes: 4448
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    n = int(input())
    a = sorted(list(map(int,input().split())))
    M = 1000005
    m = max(a)
    dp = [0]*(m+1)
    for i in range(n):
        if dp[a[i]] != 0:
            dp[a[i]] = 2
            continue
        for j in range(a[i],m+1,a[i]):
            dp[j]+=1
    cnt = 0
    for i in range(n):
        if dp[a[i]] == 1:
            cnt+=1
    print(cnt)

Measured memory_bytes: 108972
#![allow(unused_imports)]
#![allow(non_snake_case)]
use proconio::{input, fastout};
use proconio::marker::{Chars, Bytes, Usize1};

use std::collections::VecDeque;

#[fastout]
fn main() {
    input!{
        H:usize, W:usize,
        ch:Usize1, cw:Usize1,
        dh:Usize1, dw:Usize1,
        g: [String; H]
    }
    let mut G: Vec<Vec<char>> = Vec::new();
    for x in g {
        G.push(x.chars().collect());
    }
    let arr = vec![(0, 1), (1, 0), (0, -1), (-1, 0)];
    let mut dist = vec![vec![H*W; W]; H];
    dist[ch][cw] = 0;
    let mut q = VecDeque::new();
    q.push_back((ch as i32, cw as i32, 0));
    while !q.is_empty() {
        let (u, v, c) = q.pop_front().unwrap();
        if c > dist[u as usize][v as usize] { continue; };
        for &(du, dv) in &arr {
            let nu = u + du;
            let nv = v + dv;
            if 0 <= nu && nu < H as i32 && 0 <= nv && nv < W as i32 &&
            G[nu as usize][nv as usize] == '.' && dist[nu as usize][nv as usize] > c {
                dist[nu as usize][nv as usize] = c;
                q.push_front((nu, nv, c));
            }
        }
        for du in -2..3 {
            for dv in -2..3 {
                let nu = u + du;
                let nv = v + dv;
                if 0 <= nu && nu < H as i32 && 0 <= nv && nv < W as i32 &&
                G[nu as usize][nv as usize] == '.' && dist[nu as usize][nv as usize] > c + 1 {
                    dist[nu as usize][nv as usize] = c + 1;
                    q.push_back((nu, nv, c + 1));
                }
            }
        }
    }
    let ans = dist[dh][dw];
    // println!("{:?}", dist);
    println!("{}", if ans == H * W {-1} else {ans as i32});
}


Measured memory_bytes: 15128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int md=1e9+7;
int qmul(int x,int p)
{
	int res=1;
	for(;p;p>>=1,x=1LL*x*x%md)if(p&1)res=1LL*res*x%md;
	return res;
}
int fac[200010],inv[200010];
inline int C(int x,int y){return 1LL*fac[x]*inv[x-y]%md*inv[y]%md;}
int h,w,a,b;
int main()
{
	fac[0]=1;
	for(int i=1;i<=200000;i++)fac[i]=1LL*fac[i-1]*i%md;
	inv[200000]=qmul(fac[200000],md-2);
	for(int i=199999;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%md;
	scanf("%d%d%d%d",&h,&w,&a,&b);
	int ans=C(h+w-2,h-1);
	int x=h-a+1,y=b;
	while(x<=h && y)
	{
		ans=(ans+md-1LL*C(x+y-2,x-1)*C(h+w-x-y,h-x)%md)%md;
		x++;y--;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, k;
    int pos;
    cin >> n >> k;
    imfor(i, n) {
        int a;
        cin >> a;
        if (a == 1) {
            pos = i;
        }
    }
    int ans = 1;
    if (n <= k) {
        cout << 1 << endl;
    }
    else {
        n -= k;
        if (n % (k - 1) == 0) {
            ans += n / (k - 1);
        }
        else {
            ans += n / (k - 1);
            ans++;
        }
        cout << ans << endl;
    }
}

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;
}
#include <cstdint>

uintmax_t comb(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
//桁数のカウント
//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);
/////////////////////////////////////////////////////

ll n,m,sum;
cin >> n >> m;
vi a(m);
rep(i,m) cin >> a[i];
sum = accumulate(a.begin(),a.end(),0);
if(sum > n) cout << -1 << endl;
else cout << n - sum << endl;

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

Measured memory_bytes: 3700
#include <stdio.h>
int max(int a,int b){return a>b?a:b;}
int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	if(a == b)
		printf("%d", max(a,b)*2);
	else
		printf("%d", max(a,b)*2-1);
	return 0;
}

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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    ll N, L; cin >> N >> L;
    ll A[N];
    rep(i, N) cin >> A[i];
    int idx = -1;
    queue<int> ans;
    rep(i, N-1){
        if(A[i] + A[i+1] >= L) idx = i;
    }
    if(idx == -1) cout << "Impossible" << endl;
    else{
        cout << "Possible" << endl;
        //最後にidx番目の結び目を切る
        //0からN-2までの結び目が存在する
        rep(i, idx) cout << i+1 << endl;
        for(int i = N-2; i > idx; i--) cout << i+1 << endl;
        cout << idx+1 << endl;
    }
    return 0;
}

void solve(){}

Measured memory_bytes: 1664
N = int(input())
A = list(map(int,input().split()))

# N = 10**5
# A = [random.randint(0,1) for _ in range(N)]
# print('A:',A)

ans_ = [0]*(N+1)

for n1 in range(N,0,-1):
    a = A[n1-1]
    sum_ = 0
    for n2 in range(2*n1,N+1,n1):
        sum_ += ans_[n2]
    if sum_%2 == a:
        ans_[n1] = 0
        
    elif sum_%2 != a:
        ans_[n1] = 1
        
# print('ans_:',ans_)

ans_list = []  
for s_ in range(len(ans_)):
    s=ans_[s_]
    if s == 1:
        ans_list.append(s_)
        
print(len(ans_list))
if len(ans_list)>0:
    print(' '.join(map(str,ans_list)))

Measured memory_bytes: 106580
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
vector<pair<int, int>> vec;
int co[300030] = { 0 }, co1[300030] = { 0 };
vector<int> ma, ma1;
int main() {
	long long h, w, m;
	cin >> h >> w >> m;
	int s = 0, s1 = 0;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		co[x]++;
		co1[y]++;
		vec.emplace_back(make_pair(x, y));
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i <= w; i++) {
		if (co1[i] > s) {
			s = co1[i];
		}
	}
	for (int i = 0; i <= w; i++) {
		if (co1[i] == s) {
			ma.emplace_back(i);
		}
	}
	for (int i = 0; i <= h; i++) {
		if (co[i] > s1) {
			s1 = co[i];
		}
	}
	for (int i = 0; i <= h; i++) {
		if (co[i] == s1) {
			ma1.emplace_back(i);
		}
	}
	int ans = 0;
	for (int i = 0; i < ma1.size(); i++) {
		for (int j = 0; j < ma.size(); j++) {
			int count = s1 + s;
			if (binary_search(vec.begin(), vec.end(), make_pair(ma1[i], ma[j]))) {
				count--;
			}
			else {
				cout << count << endl;
				return 0;
			}
		}
	}
	cout << s1 + s - 1 << endl;
	return 0;
}


Measured memory_bytes: 12288
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
int ans=1,n,k,i=1;
int main()
{
cin>>n>>k;
while(i<=n)
{
	ans+=min(ans,k);
	i++;
}
cout<<ans;
cout<<endl;
return 0;
}


Measured memory_bytes: 384
use contest::io::Scanner;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let n = sc.next::<usize>();
    let s = sc.next::<String>();
    let mut r = 0;
    let mut b = 0;
    for c in s.chars() {
        if c == 'R' {
            r += 1;
        } else {
            b += 1;
        }
    }
    if r > b {
        println!("Yes");
    } else {
        println!("No");
    }
}
pub mod contest {
    pub mod io {
        /// Scanner
        ///
        /// # Example
        /// ```
        /// use contest::io::Scanner;
        /// let mut sc = Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
        /// assert_eq!("1".to_string(), sc.next::<String>());
        /// assert_eq!(2, sc.next());
        /// assert_eq!(3.5, sc.next());
        ///
        /// // To create a scanner from stdin:
        /// Scanner::new(std::io::stdin());
        /// ```
        use std;
        use std::io;
        use std::io::BufRead;

        pub struct Scanner<R: io::Read> {
            br: io::BufReader<R>,
            // Read tokens are stored in reversed order per line.
            buf: Vec<String>,
        }

        pub fn new<R: io::Read>(r: R) -> Scanner<R> {
            Scanner::new(r)
        }

        impl<R: io::Read> Scanner<R> {
            #[inline]
            pub fn new(r: R) -> Scanner<R> {
                Scanner {
                    br: io::BufReader::new(r),
                    buf: vec![],
                }
            }
            #[inline]
            pub fn next<T>(&mut self) -> T
            where
                T: std::str::FromStr,
                T::Err: std::fmt::Debug,
            {
                self.next_string()
                    .map(|s| s.parse::<T>().expect("Parse failed: "))
                    .expect("Unexpected EOF")
            }
            #[inline]
            pub fn next2<T1, T2>(&mut self) -> (T1, T2)
            where
                T1: std::str::FromStr,
                T2: std::str::FromStr,
                T1::Err: std::fmt::Debug,
                T2::Err: std::fmt::Debug,
            {
                (self.next(), self.next())
            }
            fn next_string(&mut self) -> Option<String> {
                self.buf.pop().or_else(|| match self.update() {
                    true => self.next_string(),
                    false => None,
                })
            }
            #[inline]
            fn update(&mut self) -> bool {
                let mut s = String::new();
                let res = self.br.read_line(&mut s);
                match res.expect("I/O error.") {
                    0 => false,
                    _ => {
                        self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                        true
                    }
                }
            }
        }

        #[test]
        fn test_next() {
            let mut sc = new("hoge".as_bytes());
            let s: String = sc.next();
            assert_eq!("hoge", s);
        }
    }
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			//long n = long.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int a = vs[0];
			int b = vs[1];
			int ans = a * b - a - b + 1;
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  string S;
  vector<int> v1;
  int tmp;
  cin >> S;
  for (int i=1;i<=S.size();i++){
    tmp=0;
    if (i == S.size()){
      if (S[i-1]=='A' || S[i-1]=='T'||S[i-1]=='G'||S[i-1]=='C'){
        tmp = 1;
      }
      v1.push_back(tmp);
      break;
    }else if (S[i-1]=='A' || S[i-1]=='T'||S[i-1]=='G'||S[i-1]=='C'){
      tmp = 1;
      for (int j=i+1; j<=S.size();j++){
        if(S[j-1]=='A'||S[j-1]=='T'||S[j-1]=='G'||S[j-1]=='C'){
          tmp += 1;
        }else{
          v1.push_back(tmp);
          break;
        }
      }
      v1.push_back(tmp);
    }
  }
  sort(v1.begin(), v1.end(),greater<int>());
  int max = v1[0];
  cout << max << '\n';
  return 0;
}


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

const ll mod=1e9+7;

ll n,m;
char mat[1001][1001];
ll dp[1001][1001];

ll solve(ll i,ll j){
    if(i>=n || j>=m){
        return 0;
    }
    if(i==n-1 && j==m-1) return 1;
    if(dp[i][j]!=-1) return dp[i][j]%mod;
    if(mat[i][j]=='#') return 0;
    ll ans=solve(i+1,j)+solve(i,j+1);
    ans%=mod;
    return dp[i][j]=ans;
}

int main() {
    
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            cin>>mat[i][j];
        }
    }

    cout<<solve(0,0)%mod<<endl;


}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#include<cstdio>
#include<cstring>
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                pe[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
/*bool isprime(ll n)
{
    if(n<2) return 0;
    if(n==2) return 1;
    else
    {
        for(int i=2; i*i<=n; i++)
            if(n%i==0) return 0;
    }
    return 1;
}*/
map<int , int >mp;
set<int  > st;
multiset<string> :: iterator it;
deque <char> q ;
int vis [10000000];
pair<int,int> a[2020];
int cnt[2];
int main()
{
    fast ;
     string s;
     cin >> s;
     for ( int i=0;i<s.sz;i++)
     {
          if(s[i]=='?')
            s[i] = 'D';
     }
    cout << s <<endl;
}










Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
 
const int INF = 1000;
 
// Applies the permutation perm on the bits of x.
int shuffle_bitmask(int len, const vector<int>& perm, int x) {
    int y = 0;
    for (int i = 0; i < len; i++) if (x&(1<<i)) y ^= 1<<perm[i];
    return y;
}
 
const int MAXLEN = 5;
int memo_shuffle_bitmask[MAXLEN+1][120][1<<MAXLEN];
int factorial[MAXLEN+1];
 
// Precompute the factorials and shuffle_bitmask.
// The precomputation of shuffle_bitmask is not necessary, but it makes the code
// much faster.
void preprocessing() {
    factorial[0] = factorial[1] = 1;
    for (int n = 2; n <= MAXLEN; n++) {
        int z = 0;
        factorial[n] = n * factorial[n-1];
        vector<int> perm(n);
        for (int i = 0; i < n; i++) perm[i] = i;
        while (next_permutation(perm.begin(), perm.end())) {
            for (int bb = 0; bb < (1<<n); bb++) {
                memo_shuffle_bitmask[n][z][bb] = shuffle_bitmask(n, perm, bb);
            }
            z++;
        }
    }
}
 
// Returns whether conf is name-preserving.
bool is_name_preserving(int len, const vector<int>& conf) {
    static bool arr[1<<MAXLEN];
    for (int bb = 0; bb < (1<<len); bb++) arr[bb] = false;
    for (int x: conf) arr[x] = true;
    for (int i = 0; i < factorial[len]-1; i++) {
        bool works = true;
        for (int x: conf) works &= arr[memo_shuffle_bitmask[len][i][x]];
        if (works) return false;
    }
    return true;
}
 
// Enumerate configurations of q distinct subsets of {0, ..., len-1}; counting how many are name-preserving.
// A configuration is identified with a q-subset of {0, 1, ..., (2^len)-1}.
int count_name_preserving(int len, int q, int last, vector<int>& curr) {
    if (q == 0) return is_name_preserving(len, curr);
    int res = 0;
    for (int i = last+1; i < (1<<len) and res/factorial[len] <= INF; i++) {
        curr.push_back(i);
        res += count_name_preserving(len, q-1, i, curr);
        curr.pop_back();
    }
    return res;
}
 
int solve(LL k, LL n) {
    if (k > n) swap(k, n);
    if (n > (1ll<<k)-n) return solve(k, (1ll<<k)-n);
    if (k > MAXLEN) return -1;
 
    vector<int> curr = {};
    int res = count_name_preserving(k, n, -1, curr) / factorial[k];
    return (res > INF)?-1:res;
}
 
int g(LL n) {
    if (n == 1) return 0;
    for (int k = 0; k <= n; k++) if ((1ll<<k) >= n and (1ll<<k)-g(k) >= n) return k;
    return -1;
}
 
int main() {
    preprocessing();
    
    LL N;
    cin >> N;
    LL res = solve(g(N), N);
    if (N == 4) res++;
    if (N == 7) res += 2;
    cout << res << "\n";
}

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

int main()
{
  int N;
  cin >> N;
  for(int i = 0; i < 30; ++i){
    for(int j = 0; j < 20; ++j){
      if(N == i*4+j*7){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}

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

using namespace std;

#define ll long long int
#define get(a) ll a; cin >> a;
#define show(a) cout << a << endl;
#define full(p) p.begin(), p.end()
#define sz(a) (ll)(a.size())
#define pb push_back

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	////////////////////////////////
	get(x);
	get(y);

	cout << x+y/2 << endl;	

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n,m;
  cin >> n >> m;
  vector<int> l(m),r(m);
  rep(i,m){
    cin >> l.at(i);
    cin >> r.at(i);
  }
  int lans = 0;
  int rans = INF;
  rep(i,m){
    lans = max(lans,l.at(i));
    rans = min(rans,r.at(i));
  }
  cout << max(rans - lans + 1,0) << endl;
}



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

struct Node{
  int key;
  struct Node* parent; //親
  struct Node* left; //左の子
  struct Node* right; //右の子
};

typedef struct Node node;

node* insert(node* r, int k) {
  node* x = r;
  node* y = NULL;
  node* z = (node*)malloc( sizeof(node) );
  z->key = k;
  z->left = NULL;
  z->right = NULL;
  z->parent = NULL;

  while( x != NULL) {
    y = x;

    if( z->key < x->key ) {
      x = x->left;
    }else {
      x = x->right;
    }

  }
  z->parent = y;

  if( y == NULL) {
    r = z;
  }else if( z->key < y->key) {
    y->left = z;
  }else {
    y->right = z;
  }

  return r;

}


void printInorder(node* r) { //左->自身->右
  
  if(r->left != NULL) {
    printInorder( r->left );
  }

  printf(" %d", r->key);

  if(r->right != NULL) {
    printInorder( r->right );
  }

}


void printPreorder(node* r) {

  printf(" %d", r->key);

  if(r->left != NULL) {
    printPreorder( r->left );
  }

  if(r->right != NULL) {
    printPreorder( r->right );
  }

}


main() {

  int m, k;
  node* r = NULL;
  char o[10];
  int i;

  //命令の数を取得
  scanf("%d", &m);

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

    //命令を取得
    scanf("%s", o);

    if(!strcmp( o, "insert")) { //挿入
      scanf("%d", &k);
      //printf("?");
      //fflush(stdout);
      r = insert( r, k);
      //printf("!");
      //fflush(stdout);
    }

    if(!strcmp( o, "print")) { //出力
      printInorder( r );
      printf("\n");

      printPreorder( r );
      printf("\n");
    }


  }

  return 0;

}

Measured memory_bytes: 24040
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    k, s = map(int, input().split())
    c = 0
    for i in range(k+1):
        for j in range(k+1):
            if 0 <= s - (i + j) <= k:
                c += 1
    print(c)


main()


Measured memory_bytes: 2940
from math import factorial
from sys import stdin


def permutations_count(n, r):
    return factorial(n) // factorial(n - r)


def main():
    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    if N == M:
        x = (factorial(N) % (10 ** 9 + 7)) * (factorial(M) % (10 ** 9 + 7))
        print((x * 2) % (10 ** 9 + 7))
    elif abs(N - M) == 1:
        x = (factorial(N) % (10 ** 9 + 7)) * (factorial(M) % (10 ** 9 + 7))
        print(x % (10 ** 9 + 7))
    else:
        print(0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4100
#include <bits/stdc++.h>
#if ONLINE_JUDGE
    #define DEBUG false
#else
    #define DEBUG true
#endif
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) std::sort(all(x))
#define REV(x) std::reverse(all(x))
#define UNIQUE(x) x.erase(std::unique(all(x)), x.end());
#define MAX(x) *std::max_element(all(x))
#define MIN(x) *std::min_element(all(x))
#define LOWitr(x, n) std::lower_bound(all(x), n)
#define UPRitr(x, n) std::upper_bound(all(x), n)
#define cii(x) int x; std::cin >> x
#define cill(x) signed long long int x; std::cin >> x
#define cis(x) std::string x; std::cin >> x
#define co(x) std::cout << x << "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) if(DEBUG) std::cout<<#x<<" : "<<(x)<<"\n"
template<class T>using V = std::vector<T>;
template<class T>using VV = std::vector<std::vector<T>>;
template<class T>using Q = std::queue<T>;
template<class T>using PQ = std::priority_queue<T>;
template<class T,class U>using P = std::pair<T, U>;
template<class T,class U>using M = std::map<T, U>;
template<class T,class U>using UM = std::unordered_map<T, U>;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T>inline void vcin(T &v){for(auto&& i : v) std::cin >> i;}
template<class T>inline void dumpv(const T& v, std::ostream& os = std::cout){
    if(DEBUG){
        os<<"{";
        std::for_each(all(v),[&os](typename T::value_type p){os<<p<<',';});
        os<<"}\n";
    }
}
using std::cin;
using std::cout;
using std::string;
using std::next_permutation;
using LL = signed long long int;
const int INF = INT_MAX, MOD = 1e9 + 7;
const LL LLINF = LLONG_MAX;
const double PI = M_PI;

void Main(){
    cill(a);
    cill(b);
    cill(c);
    cill(k);
    LL ans = 0;
    ans += std::min(a, std::max(k, (LL)0));
    k-=a;
    k-=b;
    ans -= std::min(c, std::max(k, (LL)0));
    co(ans);
}

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

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int mod = 1e9 + 7;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    map<int, int> ma;
    rep(i,n) {
        cin >> a[i];
        ma[a[i]]++;
    }
    ll ans = 1;
    for(auto p : ma){
        if(p.first == 0) continue;
        if(p.second != 2) ans = 0;
        ans *= 2;
        ans %= mod;
    }
    cout << ans << endl;
}

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



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

ll lcm(ll a,ll b){
  ll ans = (a*b)/gcd(a,b);
  return ans;
}

int main(){
  ll a,b;
  cin >> a >> b;
  cout << lcm(a,b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long i,a,b,t,n;
int main()
{
	scanf("%lld%lld",&a,&b);
	n=a*b;
	if(a<b)
	{
		t=a;
		a=b;
		b=t;
	}
	t=a%b;
	while(t)
	{
		a=b;
		b=t;
		t=a%b;
	}
	printf("%lld",n/b);
	return 0;
}

Measured memory_bytes: 256
const MOD: usize = 1e9 as usize + 7;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let _: usize = sc.read();
    let mut count = vec![0; 26];
    let s: Vec<char> = sc.chars();
    for c in s.into_iter() {
        count[c as usize - 'a' as usize] += 1;
    }

    let mut ans = 1;
    for i in 0..26 {
        ans *= count[i] + 1;
        ans %= MOD;
    }
    println!("{}", ans - 1);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
int main() {
	long long N, M,tmp;
	long long ans = 0;
	scanf("%lld%lld", &N, &M);
	if (N > M) {
		tmp = N;
		N = M;
		M = tmp;
	}
	if (N == 1 && M == 1) {
		ans = 1;
	}
	else if (N == 1 && M != 1)
	{
		ans = M - 2;
	}
	else if (N >= 2) {
		ans = (N - 2)*(M - 2);
	}
	printf("%lld\n", ans);
	return 0;
}

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

int n;
int a[20000];
int b[20000];
int c[20000];

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>c[i];
    a[i]=i*30000+1;
    b[i]=1e9-a[i];
  }
  for(int i=0;i<n;i++){
    int p=c[i]-1;
    a[p]+=i;
  }
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<a[i];
  }
  cout<<endl;
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<b[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 896