akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    string s; cin>>s;
    int n=s.size();
    int sum=0;
    for(int i=0; i<n; i++){
        sum+=(s[i]-'0');
    }
    sum%=9;
    if(sum==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
string s;
ll n,p;
ll cnt[N];
int main() {
	ll i,sum=0,c=1,ans=0;
	cin>>n>>p>>s;
	if (p==2||p==5) {
		for (i=n-1;i>=0;i--)
			if ((s[i]-'0')%p==0) ans+=i+1;
		cout<<ans<<endl;
		return 0;
	}
//	for (i=0;i<p;i++) cnt[i]=1;
	cnt[0]=1;
	for (i=n-1;i>=0;i--) {
		sum=(sum+(s[i]-'0')*c)%p;
		cnt[sum]++;
		c=(c*10)%p;
	}
	ans=0;
	for (i=0;i<p;i++)
		ans+=cnt[i]*(cnt[i]-1)/2;
	cout<<ans<<endl;
	return 0;
}

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

void bit_16to2(char);

int bit_2[32],a;

int main(){

  char bit_16[8];
  long long b,n,ans_1,ans_2,c=5000000;
  bool check1,check2;

  cin >>n;
  
  for(int j=0 ; j < n ; j++){
 
    check1=false;
    check2=false;
    a=0;
    b=8388608;
    c=5000000;
    ans_1=0;
    ans_2=0;
  
    for(int i=0 ; i < 8 ; i++)cin >>bit_16[i];
    
    for(int i=0 ; i < 8 ; i++)bit_16to2(bit_16[i]);
    
    for(int i=1 ; i < 25 ; i++){
      if(bit_2[i]==1){
	ans_1+=b;
      }
      b/=2;
    }
    for(int i=25 ; i < 32 ; i++){
      if(bit_2[i]==1){
	ans_2+=c;
      }
      c/=2;
    }
    
    //cout <<ans_2<<endl;
    
    if(ans_2 != 0 && ans_2 < 1000000)check1=true;
    if(ans_2 != 0 && ans_2 < 100000)check2=true;
    
    
    while(1){
      if(ans_2 !=0 && ans_2 % 10 == 0){
	ans_2/=10;
      }else{
	break;
      }
    }

    
    if(bit_2[0] == 1)cout <<"-";
    
    cout <<ans_1<<".";
    if(check1)cout <<"0";
    if(check2)cout <<"0";
    cout <<ans_2;
    cout <<endl;
  }
  return 0;
  
}
void bit_16to2(char c){

  int bit,b=8;

  if(c >= 'a' && c <= 'f'){
    bit=c-'a'+10;
  }else{
    bit=c-'0';
  }
  
  for(int i=0 ; i < 4 ; i++){
    if(bit / b > 0){
      bit_2[a]=1;
      bit%=b;
    }else{
      bit_2[a]=0;
    }
    a++;
    b/=2;
  }

}

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

int compare(const void *a,const void *b){
	
	return *(int*)b-*(int*)a;
}


int main(){
	
	int N,d[110],i,dansuu=1;
	scanf("%d",&N);
	
	for(i=0;i<N;i++){
		
		scanf("%d",&d[i]);
	}
	
	qsort(d,N,sizeof(int),compare);
	
	for(i=1;i<N;i++){
		
		if(d[i]<d[i-1]){
			
			dansuu++;
		}
		
	}
	
	printf("\n%d\n\n",dansuu);
	
	
	return 0;
}

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

int main(){
    ll n;
    vector<ll> abi(5);
    cin>>n;
    //ll t1=n,t2=0,t3=0,t4=0,t5=0,t6=0,ans=0;
    for(int i=0;i<5;i++){
        cin>>abi[i];
    }
    ll ans=0,now=0;
    for(int i=0;i<5;i++){
        if(n%abi[i]==0){
            now=n/abi[i];
            if(now>ans){
                ans=now;
            }
        }else{
            now=n/abi[i]+1;
            if(now>ans){
                ans=now;
            }
        }
    }
    cout<<ans+4<<endl;
}

Measured memory_bytes: 256
program A325A
    implicit none
    integer(8)::K,N,i,ans
    integer(8),allocatable,dimension(:)::L
    read*,N,K
    allocate(L(N))
    read*,L
    ans=0
    call heapsort(N,L)

    do i=0,K-1
        ans=ans+L(N-i)
    end do

    print'(i0)',ans
end program A325A

subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
  end subroutine heapsort

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> a(N);
	for (Int i = 0; i < N; i++) {
		cin >> a[i];
	}

	pair<Int, Int> plus(0, -1);//プラスの最大値（値、インデックス）
	pair<Int, Int> minus(0, -1);//マイナスの最小値（値、インデックス）

	for (Int i = 0; i < N; i++) {
		if (a[i] < 0) {
			if (a[i] < minus.first) {
				minus.first = a[i];
				minus.second = i;
			}
		}
		else {
			if (a[i] > plus.first) {
				plus.first = a[i];
				plus.second = i;
			}
		}
	}

	if (abs(minus.first) > plus.first) {

		cout << 2 * N - 1 << "\n";

		if (minus.second == -1)minus.second++;
		for (Int i = 0; i < N; i++) {
			cout << minus.second + 1 << " " << i + 1 << "\n";
		}

		for (Int i = N-1; i > 0; i--) {
			cout << i + 1 << " " << i << "\n";
		}


	}
	else {
		cout << 2 * N - 1 << "\n";

		if (plus.second == -1)plus.second++;
		for (Int i = 0; i < N; i++) {
			cout << plus.second + 1 << " " << i + 1 << "\n";
		}

		for (Int i = 0; i < N-1; i++) {
			cout << i + 1 << " " << i+2 << "\n";
		}

	}

}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>

using namespace std;
using vec = vector<int>;
using mat = vector<vec>;

int main()
{
	int N, T;
	cin >> N >> T;

	mat dp(N + 1, vec(T + 1));
	vector<pair<int, int>> Dish;

	for (int i = 0; i < N; ++i)
	{
		pair<int, int> p;
		cin >> p.first >> p.second;
		Dish.emplace_back(p);
	}

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

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < T + 1; ++j)
		{
			int k = min(j + Dish[i].first, T);
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if (j != T)
			{
				dp[i + 1][k] = dp[i][j] + Dish[i].second;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < T + 1; ++i)
	{
		ans = max(ans, dp[N][i]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 35584
// https://atcoder.jp/contests/abc138/tasks/abc138_e
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn ctoi(c: char) -> usize {
    if 'a' <= c && c <= 'z' {
        ((c as u8) - ('a' as u8)) as usize
    } else {
        unreachable!("wrong character");
    }
}

fn main() {
    input! {
        s: chars,
        t: chars
    };
    let n = s.len();
    let mut s = s;
    let mut ss = s.clone();
    ss.append(&mut s);

    let mut next = dvec!(0; n, 26);
    let mut last = vec![2*n; 26];
    for i in (0..2*n).rev() {
        if i < n {
            for j in 0..26 {
                next[i][j] = last[j];
            }
        }
        last[ctoi(ss[i])] = i;
    }

    let mut now = 0;
    let mut total = 0;
    let mut ok = true;
    let mut first = true;
    for c in t {
        if first && c == ss[0] {
            first = false;
            continue;
        }
        first = false;

        let to = next[now][ctoi(c)];
        if to == 2*n {
            ok = false;
            break;
        }
        total += to - now;
        now = to % n;
    }
    if ok {
        println!("{}", total+1);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 33020
var c,y,next,first,dist,q:array[0..500020] of int64;
var v:array[0..500020] of boolean;
var n,m,i,j,s,x,y1,z,tot,ans:longint;
procedure add(x,y1,z:longint);
begin
  inc(tot);next[tot]:=first[x];first[x]:=tot;y[tot]:=y1;c[tot]:=z;
end;
procedure spfa(s:longint);
var i,now,h,t:longint;
begin
  for i:=0 to 200 do begin v[i]:=false;dist[i]:=2147483647;end;dist[s]:=0;
  h:=0;t:=1;v[s]:=true;q[1]:=s;
  while h<t do
  begin
    inc(h);now:=q[h];i:=first[now];
    while i<>-1 do
    begin
      if dist[y[i]]>dist[now]+c[i] then
      begin
        dist[y[i]]:=dist[now]+c[i];
        if not v[y[i]] then
        begin
          inc(t);q[t]:=y[i];v[y[i]]:=true;
        end;
      end;
      i:=next[i];
    end;
    v[now]:=false;
  end;
end;
begin
  read(n,m);
  for i:=0 to 200 do first[i]:=-1;
  for i:=0 to 9 do for j:=0 to 9 do begin read(x);if x<>0 then
  begin //add(i+1,j+1,x);
  add(j+1,i+1,x);
  end;end;
  spfa(2);
  //for i:=1 to 10 do writeln(dist[i]);ans:=0;
  for i:=1 to n do for j:=1 to m do begin read(x);
  if x>=0 then inc(ans,dist[x+1]);end;writeln(ans);
end.


Measured memory_bytes: 10368
S = input()
flag = 0
char_num = len(S)
chk = char_num%2

#even
for i in range(1,int(char_num/2)+1):
  #  print(S[i*2-1],(i*2-1))
    if (S[i*2-1]=='R'):
        print('No')
        flag = 1
        break

            
#odd
if flag == 0:
    for i in range(int(char_num/2)):
       # print(S[(i)*2],i*2)
        if (S[i*2]=='L'):
            print('No')
            flag = 1
            break
if chk == 1:  
   # print(S[-1],char_num-1)
    if flag == 0:
        if (S[-1]=='L'):
            print('No')
            flag = 1

if flag == 0:
        print('Yes')


Measured memory_bytes: 3064
x = int(input())
#print(x)

for b in range(121):
  for a in range(b+1,122):
    kx = (a**5) - (b**5)
    if kx == x:
      print('{} {}'.format(a,b))
      exit()
    elif kx > x:
      break

for b in range(121):
  for a in range(b+1,122):
    kx = (a**5) + (b**5)
    if kx == x:
      print('{} {}'.format(a,-b))
      exit()
    elif kx > x:
      break


Measured memory_bytes: 65176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}

using namespace std;

int main(){
	int N,A,B;
	cin>>N>>A>>B;
	if((B-A)%2 == 0){
		cout<<"Alice"<<endl;
	} else {
		cout<<"Borys"<<endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<limits.h>
#include<string>
#include<vector>
#include<functional>
using namespace std;

signed main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0])puts("YES");
	else puts("NO");
}

Measured memory_bytes: 256
from collections import deque

n,q=map(int,input().split())
que=deque([])
tmcnt=0

for i in range(n):
    name,timer=input().split()
    que.append([name,int(timer)])

while len(que)!=0:
    now=que.popleft()
    nt=now[1]-q
    if nt<=0:
        tmcnt+=now[1]
        print(now[0],tmcnt)
    else:
        now[1]-=q
        tmcnt+=q
        que.append(now)


Measured memory_bytes: 13276
#include<iostream>
#include<algorithm>
using namespace std;
int dp[500][500];
int top[500];
int main(){
    int h,w;
    char z;
    while(true){
    cin>>h>>w;
    if(h==0&&w==0)break;
    for(int i=0;i<500;i++)top[i]=0;
    for(int j=0;j<w;j++){
        cin>>z;
        dp[0][j]=1;
        if(z=='*')dp[0][j]=0;
        top[j]=max(top[j],dp[0][j]);
    }
    for(int i=1;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>z;
            dp[i][j]=dp[i-1][j]+1;
            if(z=='*')dp[i][j]=0;
            top[i]=max(top[i],dp[i][j]);
        }
    }
    bool t[500];
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)t[j]=true;
        for(int j=1;j<=top[i];j++){
            for(int k=0;k<w;k++)if(dp[i][k]==j-1)t[k]=false;
            int best=0,cnt=0;
            for(int k=0;k<w;k++){
                if(t[k])cnt++;
                else{
                    best=max(best,cnt);
                    cnt=0;
                }
            }
            best=max(best,cnt);
            ans=max(ans,best*j);
        }
    }
    cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 2136
N,K=map(int,input().split())
H=[]
for _ in range(N):
    H.append(int(input()))
H.sort()
min = 1e12
for i in range(N-(K-1)):
    diff = H[i+K-1] - H[i]
    if diff < min:
        min = diff

print(min)

Measured memory_bytes: 80868
#include <bits/stdc++.h>
using namespace std ;
template < class R > inline void Readin( R &K ) {
	K = 0 ; bool F = false ; char C = getchar() ; while( C < '0' or C > '9' ) { if( C == '-' ) F = true ; C = getchar() ; }
	while( C <= '9' and C >= '0' ) K = ( K << 1 ) + ( K << 3 ) + C - '0' , C = getchar() ; if( F ) K = -K ;
}
template < class R > inline void Checkmax( R &A , R B ) {
	if( A < B ) A = B ;
}
template < class R > inline void Checkmin( R &A , R B ) {
	if( A > B ) A = B ;
}
const int Mod = 1e9 + 7 ;
const int MaxN = 100000 + 10 ;
inline void Moding( int &A ) {
	if( A >= Mod ) A -= Mod ;
	if( A < 0 ) A += Mod ;
}
inline int Pow( int A , int B ) {
	register int Ans = 1 ;
	while( B ) {
		if( B & 1 ) Ans = 1ll * Ans * A % Mod ;
		A = 1ll * A * A % Mod ;
		B >>= 1 ;
	}
	return Ans ;
}
int __Fac[MaxN] , __Inv[MaxN] ;
inline void __C_Init() {
	register int N = MaxN - 10 ;
	__Fac[0] = __Inv[0] = 1 ;
	for(register int i = 0 ; ++i <= N ; )
		__Fac[i] = 1ll * __Fac[i-1] * i % Mod ;
	__Inv[N] = Pow( __Fac[N] , Mod - 2 ) ;
	for(register int i = N ; --i ; )
		__Inv[i] = 1ll * __Inv[i+1] * (i+1) % Mod ;
}
inline int __C( int N , int M ) {
	return 1ll * __Fac[M] * __Inv[N] % Mod * __Inv[M-N] % Mod ;
}
int N ;
int M ;
int A[MaxN] ;
int C[MaxN] ;
int main() {
	Readin( N ) ;
	Readin( M ) ;
	for(register int i = 0 ; ++i <= N ; )
		A[i] = 1 ;
	C[1] = 1 ;
	for(register int i = 0 ; ++i <= M ; ) {
		register int X , Y ;
		Readin( X ) ;
		Readin( Y ) ;
		C[Y] |= C[X] ;
		++A[Y] ;
		if( --A[X] == 0 ) C[X] = 0 ;
	}
	register int Ans = 0 ;
	for(register int i = 0 ; ++i <= N ; )
		Ans += C[i] ;
	return not printf( "%d\n" , Ans ) ;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222


ll a[MAX * 5];


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


  cin >> n;
  a[n] = 1;
  ll cnt = 1, cur = n;
  while (1) {
    cnt++;
    if (cur % 2) {
      cur = 3 * cur + 1;
    }
    else {
      cur /= 2;
    }
    if (a[cur]) {
      ans = cnt;
      break;
    }
    else a[cur] = cnt;
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int manx=5e5+50;
char a[manx];
set<int>s[50];
int x,l,r,q,n;
char c;
int main()
{
    int n; scanf("%d",&n);
    scanf("%s%d",a+1,&q);
    for(int i=1;i<=n;i++)
        s[a[i]-'a'].insert(i);
    while(q--)
    {
        scanf("%d",&x);
        if(x==2){
            scanf("%d%d",&l,&r);
            int ans=0;
            for(int i=0;i<26;i++)
            {
                auto it=s[i].lower_bound(l);
                if(it!=s[i].end()&&*it<=r) ans++;
            }
            printf("%d\n",ans);
        }
        else if(x==1){
            cin>>l>>c;
            s[a[l]-'a'].erase(l);
            s[c-'a'].insert(l);
            a[l]=c;
        }
    }
    return 0;
}


Measured memory_bytes: 24192
#include<bits/stdc++.h>
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int64_t>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x : a) cin>> x
#define endl           '\n'
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    int k,c=0,s;cin>>k>>s;
    for(int i=0;i<=k;++i){
    	for(int j=0;j<=k;++j){
    		if(s-i-j>=0 and s-i-j<=k) c++;
    	}
    }cout<<c;
    return 0;
}
    

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

typedef long long LL;

const int N = 4010;
const LL mod = 998244353;

int n, m;

LL C[N][N], pow[N];

void init()
{
	C[0][0] = 1;
	for (int i = 1; i <= n + m; ++ i)
	{
		C[i][0] = 1;
		for (int j = 1; j <= i; ++ j)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) %  mod;
	}
	pow[0] = 1;
	for (int i = 1; i <= m; ++ i) pow[i] = pow[i - 1] * 2 % mod;
}

LL calc(int k, int x, int y) { return C[k + y - 1][x + y - 1]; }

int main()
{
	scanf("%d %d", &m, &n);
	init();
	for (int i = 2; i <= m << 1; ++ i)
	{
		LL ans = 0;
		int p = 0;
		for (int j = 1; j <= m; ++ j)
		{
			if (i - j <= j) break;
			p += 1 <= i - j && i - j <= m;
		}
		if (i & 1)
		{
			for (int q = 0; q <= p; ++ q)
				(ans += C[p][q] * pow[q] % mod * calc(n, q, m - (p << 1)) % mod) %= mod;
		}
		else
		{
			for (int q = 0; q <= p; ++ q)
			{
				(ans += C[p][q] * pow[q] % mod * calc(n, q, m - (p << 1) - 1) % mod) %= mod;
				(ans += C[p][q] * pow[q] % mod * calc(n - 1, q, m - (p << 1) - 1) % mod) %= mod;
			}
		}
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 123776
import java.util.Arrays;
import java.util.Scanner;

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

	int N;
	int d[];
	public void run() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		d = new int[N];
		for(int i=0; i<N; i++) d[i] = sc.nextInt();
		Arrays.sort(d);
		int j = uniq(d);
		System.out.println(j);
		sc.close();
	}

	private int uniq(int d[]) {
		int j=1;
		for(int i=1; i<N; i++) {
			if(d[j-1] < d[i]) {
				d[j++] = d[i];
			}
		}
		return j;
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N;
  cin >> N;
  vector<i64> A(N);
  for (i64 i = 0; i < N; i++)
    cin >> A[i];
  map<i64, i64> m;
  auto pri = [&](i64 i) {
    i64 tmp = A[i];
    for (long long a = 2; a * a <= tmp; a++)
    {
      if (tmp % a != 0)
        continue;
      while (tmp % a == 0)
        tmp /= a;
      m[a]++;
    }
    if (tmp != 1)
      m[tmp]++;
    return 0;
  };
  for (i64 i = 0; i < N; i++)
    pri(i);
  bool p = true;
  for (pair<i64, i64> i : m)
    if (i.second != 1)
      p = false;
  if (p)
  {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  i64 g = gcd(A[0], A[1]);
  for (i64 i = 2; i < N; i++)
    g = gcd(g, A[i]);
  if (g == 1)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}


Measured memory_bytes: 15788
n = int(input())
ls=[int(input()) for i in range(n)]
maxn = max(ls)
ans=[maxn]*n
nma = ls.index(maxn)
ls2=ls.copy()
ls2.remove(maxn) 
maxcel= max(ls2)
del ans[nma]
ans.insert(nma,maxcel)
a='\n'.join(map(str,ans))
print(a)

Measured memory_bytes: 28232
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <array>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;

typedef pair<int,int> pii;
typedef array<int,3> ai3;

const double EPS = 1e-8;

vector<ai3> pts;

bool lessthan(int a, int b){
	return pts[a] < pts[b];
}

bool lessthan(const pii &a, const pii &b){
	if(lessthan(a.first, b.first)){
		return true;
	}
	if(lessthan(b.first, a.first)){
		return false;
	}
	return lessthan(a.second, b.second);
}

double abs(const ai3 &p){
	return sqrt(p[0] * p[0] + p[1] * p[1] + p[2] * p[2] + 0.0);
}

double eucdist(int a, int b){
	double ta = abs(pts[a]), tb = abs(pts[b]);
	double sum = 0.0;
	for(int i = 0; i < 3; ++i){
		double d = pts[a][i] / ta - pts[b][i] / tb;
		sum += d * d;
	}
	return sqrt(sum);
}

ai3 grid(int a, double d){
	d *= abs(pts[a]);
	ai3 ret;
	for(int i = 0; i < 3; ++i){
		ret[i] = pts[a][i] / d;
	}
	return ret;
}

pii solve(int m, int n, int S, int W){
	pts.resize(m + n);
	for(int i = 0; i < m; ++i){
		scanf("%d%d%d", &pts[i][0], &pts[i][1], &pts[i][2]);
	}
	int g = S;
	for(int i = m; i < m + n; ++i){
		pts[i] = ai3{(g / 7) % 100 + 1, (g / 700) % 100 + 1, (g / 70000) % 100 + 1};
		if(g % 2 == 0){ g /= 2; }
		else{ g = (g / 2) ^ W; }
	}
	
	random_shuffle(pts.begin(), pts.end());

	map<ai3,vector<int> > mp;
	pii ans;
	double mdis = 1e8;
	for(int i = 0; i < m + n; ++i){
		double tdis = mdis;
		ai3 gi = grid(i, mdis);
		for(int dx = -1; dx <= 1; ++dx)
		for(int dy = -1; dy <= 1; ++dy)
		for(int dz = -1; dz <= 1; ++dz){
			auto it = mp.find(ai3{gi[0] + dx, gi[1] + dy, gi[2] + dz});
			if(it != mp.end()){
				for(int k : it->second){
					double ds = eucdist(i, k);
					if(ds < EPS){ continue; }
					pii pr = (lessthan(i, k) ? pii(i, k) : pii(k, i));
					if(ds + EPS < tdis){
						tdis = ds;
						ans = pr;
					}
					else if(abs(ds - tdis) < EPS && lessthan(pr, ans)){
						ans = pr;
					}
				}
			}
		}
		
		if(tdis + EPS < mdis){
			mdis = tdis;
			mp.clear();
			for(int j = 0; j < i; ++j){
				mp[grid(j, mdis)].push_back(j);
			}
		}
		mp[grid(i, mdis)].push_back(i);
	}
	
	return ans;
}

int main(){
	srand(time(0));

	int m, n, S, W;
	while(scanf("%d%d%d%d", &m, &n, &S, &W), S){
		pii ans = solve(m, n, S, W);
		int a = ans.first, b = ans.second;
		printf("%d %d %d %d %d %d\n",
			pts[a][0], pts[a][1], pts[a][2], pts[b][0], pts[b][1], pts[b][2]);
	}
}

Measured memory_bytes: 12352
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define endl '\n'
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define F first
#define S second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<(int)n;i++)
#define pb push_back
#define eb emplace_back
#define mp(a,b) make_pair(a,b)
#define cans cout<<ans<<endl
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<'('<<P.F<<','<<P.S<<')';
    return out;
}

//}}}
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
#define maxn 100005
int dp[maxn];
int arr[maxn];

int32_t main(){
    int n;
    cin>>n;
    rep(i,n)
        cin>>arr[i];
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);
    for(int i=2;i<n;i++){
        dp[i]=min(
            dp[i-2]+abs(arr[i]-arr[i-2]),
            dp[i-1]+abs(arr[i]-arr[i-1])
        );
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

constexpr int64_t M = 1000000007L;

main() {
    int64_t n, m;
    cin >> n >> m;
    
    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    vector<int64_t> b(m);
    for (auto&& bb : b) {
        cin >> bb;
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
    for (auto i : irange(1L, n)) {
        if (a[i - 1] == a[i]) {
            cout << "0" << endl;
            return 0;
        }
    }

    for (auto i : irange(1L, m)) {
        if (b[i - 1] == b[i]) {
            cout << "0" << endl;
            return 0;
        }
    }

    int64_t ans = 1;
    for (auto i : irange(1L, n * m + 1)) {
        auto ita = partition_point(a.begin(), a.end(), [i](int64_t aa) {
            return aa < i;
        });

        if (ita == a.end()) {
            cout << "0" << endl;
            return 0;
        }

        auto itb = partition_point(b.begin(), b.end(), [i](int64_t bb) {
            return bb < i;
        });

        if (itb == b.end()) {
            cout << "0" << endl;
            return 0;
        }

        auto va = *ita;
        auto vb = *itb;

        auto rem = (a.end() - ita) * (b.end() - itb) - (n * m - i);
        if (rem <= 0) {
            cout << "0" << endl;
            return 0;
        }

        if (va == i && vb == i) {
            // NOP
        } else if (va == i) {
            ans = (ans * (b.end() - itb)) % M;
        } else if (vb == i) {
            ans = (ans * (a.end() - ita)) % M;
        } else {
            ans = ans * ((a.end() - ita) * (b.end() - itb) - (n * m - i)) % M;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
m=[];M=[]
for i in range(n):
    a,s=map(int,input().split())
    m.append(a);M.append(s)
m.sort();M.sort()
if n%2:
    print(M[n//2]-m[n//2]+1)
else:
    print(M[n//2]+M[n//2-1]-m[n//2]-m[n//2-1]+1)

Measured memory_bytes: 99020
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a>=1 && a<=9 && b>=1 && b<=9)
	cout<<a*b<<endl;
	else 
	cout<<-1<<endl;
	return 0;
 } 

Measured memory_bytes: 256
/******************************************************************************
 
рассвет. 
 
*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define pll pair <lli,lli> 
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (int i = a; i < (n); ++i)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
 
const lli MOD=1e9+7;
const lli MAXN=2e5+1;
const ld PI=acos(-1);

ld counted=0.0;
ld ans=0.0;

ld rass(pair <ld,ld> a,pair <ld,ld> b){
    ld f=sqrt((a.fst-b.fst)*(a.fst-b.fst)+(a.sec-b.sec)*(a.sec-b.sec));
    return f;
}

void dfs(int v,int count,int n,ld dist,vb &used,vector <pair <ld,ld>> &a){
    if(count==n-1){
        ans=(ans*counted+dist)/(counted+(ld)1.0);
        counted+=(ld)1.0;
    }
    else{
        used[v]=1;
        fr(i,n){
            if(!used[i]){
                dfs(i,count+1,n,dist+rass(a[v],a[i]),used,a);
            }
        }
        used[v]=0;
    }
}

int main(){
    rapgame
    //freopen("brokeday.in", "r", stdin);
    //freopen("richday.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        read(n);
        vector <pair <ld,ld>> a(n);
        vb used(n);
        fr(i,n){
            cin >> a[i].fst >> a[i].sec;
        }
        fr(i,n){ 
            used.assign(n,0);
            dfs(i,0,n,(ld)0.0,used,a);
        }
        cout << fixed << setprecision(30) << ans;
    }
    return 0;
}

Measured memory_bytes: 3744
ToNode = Struct.new(:id, :weight)

_ = gets

$graph       = {}
$open_list   = []
$closed_list = []

while (line = gets)
  node_id, _, *nodes = line.split(' ').map(&:to_i)
  $graph[node_id] = nodes.each_slice(2).map{|id, weight| ToNode.new(id, weight)}
  $open_list.push(node_id)
end

$visited_nodes = []



$start_node_id = 0
# Min Distance '0' to `key`
$weights = {$start_node_id => 0}
$visited_nodes.push($start_node_id)


loop do
  # Node which should be visited
  next_visit_node =
    $visited_nodes
      .flat_map{|node_id|
        to_nodes = $graph[node_id]
        w        = $weights[node_id]
        to_nodes.map{|n| {id: n.id, weight: w + n.weight} }
      }
      .reject{|e| $visited_nodes.include?(e[:id])}
      .min_by{|e| e[:weight]}

  if next_visit_node.nil?
    break
  end

  $visited_nodes.push(next_visit_node[:id])
  $weights[next_visit_node[:id]] = next_visit_node[:weight]
end

$weights
  .sort_by{|k, v| k}
  .each{|node, weight|
    puts("#{node} #{weight}")
  }


Measured memory_bytes: 9864
package main
import . "fmt"
func main() {
  var n,x,y,k int
  var a []int
  Scan(&n)
  a = make([]int,n)
  for i:=0;i<n;i++ { Scan(&a[i]) }
  x,y = 0,0
  k = 2
  for j:=1;j<=29;j++ {
    for i:=0;i<n;i++ {
      if a[i]%k == 0 { x++ }
    }
    if x == y { break }
    k *= 2
    y = x
  }
  Println(x)
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define VCIN(x) for(auto&youso:(x))cin >> (youso)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
int main(){
    CIN(N);CIN(x);
    V<int> vec1(N),vec2;
    VCIN(vec1);
    LL ans = 0;
    REP(a,N){
        if(vec1.at(a)>x){
            vec2.pb(x);
        }else{
            vec2.pb(vec1.at(a));
        }
    }
    REP(a,N-1){
        if(vec2.at(a)+vec2.at(a+1)>x){
            if(vec2.at(a)+vec2.at(a+1)-x<vec2.at(a+1)){
                vec2.at(a+1)-=(vec2.at(a)+vec2.at(a+1)-x);
            }else{
                vec2.at(a)-=(vec2.at(a)+vec2.at(a+1)-x)-vec2.at(a+1);
                vec2.at(a+1)=0;
            }
        }
    }
    REP(a,N){
        ans += vec1.at(a)-vec2.at(a);
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 1276
#include <stdio.h>
#define swap(a, b) (a ^= b, b ^= a, a ^= b)

int n;
char s[200010];

int main() {
	scanf("%d%s", &n, s);
	int i = 0, j = n - 1, ans = 0;
	while (i <= j) {
		while (s[i] == 'R') ++i;
		while (s[j] == 'W') --j;
		if (i <= j)
			swap(s[i], s[j]), ++i, --j, ++ans;
	}
	printf("%d\n", ans);
	return 0;
}



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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;cin >> n;
	ll i=1;
	while(i*i<=n) i++;
	i--;
	cout << i*i << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
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(){
  ll n;
  cin>>n;
  vll t(n);
  ll ans=0;
  rep(i,n) cin>>t[i];
  ans=t[0];
  for(int i=1;i<n;i++){
    ans=lcm(ans,t[i]);
  }
  COUT(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <complex>
#include <vector>
#include <set>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
typedef complex<double> P;

struct Edge {
    int u, v, next;
    Edge() {}
    Edge(int _u, int _v) : u(_u), v(_v) {}
};

struct Graph {
    int n, m;
    vector<int> head;
    vector<Edge> es;
    Graph(int _n) : n(_n), m(0), head(_n, -1) {}
    void add(const Edge& e) {
        es.push_back(e);
        es.back().next = head[e.u];
        head[e.u] = m++;
    }
};

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

int H, W, n, col[64][16];
char f[64][16];
int cx[1024], cnt[1024];

void draw(int i, int j, int c) {
    if(col[i][j]!=-1) return;
    col[i][j] = c;
    rep(d, 4) {
        const int x = i+dx[d], y = j+dy[d];
        if(x>=0 && x<H && y>=0 && y<W && f[i][j]==f[x][y]) draw(x, y, c);
    }
}

bool rec(const Graph& g, int ix) {
    cx[ix] = 0;
    cnt[ix] = 0;
    set<int> vis;
    for(int x=g.head[ix]; x!=-1; x=g.es[x].next) {
        const int to = g.es[x].v;
        if(vis.count(to)) continue;
        vis.insert(to);
        if(rec(g, to)==false) return false;
        cx[ix] += cx[to];
        cnt[ix] += cnt[to];
    }
    int minx = 2*W+1, maxx = -1;
    rep(i, H) rep(j, W) if(col[i][j]==ix) {
        cx[ix] += 2*j+1;
        cnt[ix] += 1;
        if(i==H-1 || (col[i+1][j]!=-1 && col[i+1][j]!=ix)) {
            minx = min(minx, 2*j);
            maxx = max(maxx, 2*(j+1));
        }
    }
    return minx*cnt[ix]<cx[ix] && cx[ix]<maxx*cnt[ix];
}

int main() {
    for(;;) {
        scanf("%d%d", &W, &H);
        if(W==0 && H==0) return 0;
        rep(i, H) rep(j, W) scanf(" %c", f[i]+j);
        n = 0;
        memset(col, -1, sizeof(col));
        rep(i, H) rep(j, W) if(f[i][j]!='.' && col[i][j]==-1) draw(i, j, n++);
        Graph g(n);
        rep(i, H-1) rep(j, W) if(col[i][j]!=-1) {
            if(col[i+1][j]!=-1 && col[i+1][j]!=col[i][j]) {
                g.add(Edge(col[i+1][j], col[i][j]));
            }
        }
        rep(i, W) if(col[H-1][i]!=-1) {
            puts(rec(g, col[H-1][i]) ? "STABLE" : "UNSTABLE");
            break;
        }
    }
}

Measured memory_bytes: 0
use std;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn a_payment() {
    let n = read::<i32>();
    let reminder = n % 1000;
    let res = if reminder == 0 { 0 } else { 1000 - reminder};
    println!("{}", res);
}

fn main() {
    a_payment();
}


Measured memory_bytes: 2128
// author: Saman Mahdanian
#include <bits/stdc++.h>

using namespace std;
const int N = 600;
const int MOD = 1e9 + 7;

void _psum (int &, int);
int _sum (int, int);
int _mul (int, int);
int _pow (int, int);
int gcd (int, int);

int n, m, k, inv[N], f[N], res[N];
vector <int> X;

int x[] = {0, 0, -1, +1};
int y[] = {-1, +1, 0, 0};
string s[N];
int t[N][N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		t[i][0] = 1;
		t[i][m - 1] = 2;
	}
	
	for (int i = 0; i < n; i++)
		for (int j = 1; j < m - 1; j++)
			t[i][j] = (i & 1) + 1;

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			if (c == '#')
				t[i][j] = 3;
		}

	for (int i = 0; i < n; i++, cout << '\n')
		for (int j = 0; j < m; j++)
			cout << (t[i][j] & 1? '#': '.');

	cout << '\n';
	for (int i = 0; i < n; i++, cout << '\n')
		for (int j = 0; j < m; j++)
			cout << (t[i][j] & 2? '#': '.');
}

int gcd (int a, int b) {
	return !b? a : gcd (b, a % b);
}

// int choose (int r, int k) {
// 	return _mul (f[k], _mul(inv[r], inv[k - r]));
// }

void _psum (int &a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

int _sum (int a, int b) {
	return a + b - (a + b >= MOD? MOD : 0);
}

int _mul (int a, int b) {
	return 1LL * a * b % MOD;
}

int _pow (int a, int b) {
	if (!b) 
		return 1;
	int res = _pow (a, b >> 1);
	res = _mul (res, res);
	if (b & 1)
		res = _mul (res, a);
	return res;
}

// SamMHD :: Jun27-2019 :: Another Day with Shayan...

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

int main()
{
    int n;
    cin >> n;
    string S;
    cin >> S;
    vector<vector<int>> A(n, vector<int>(3));
    map<char, int> mp;
    mp['R'] = 0; mp['G'] = 1; mp['B'] = 2;
    for(int i = 0; i < n; i++)
    {
        int j = mp[S[i]];
        if(i > 0)
        {
            A[i] = A[i - 1];
            A[i][j]++;
        }
        else
            A[i][j] = 1;
    }
    long long count = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            if(S[i] == S[j])
                continue;
            char c = 'R';
            set<char> s;
            s.insert(S[i]);
            s.insert(S[j]);
            if(s.find('R') == s.end())
                c = 'R';
            if(s.find('G') == s.end())
                c = 'G';
            if(s.find('B') == s.end())
                c = 'B';
            int rest = 0;
            int k = mp[c];
            rest = A[n - 1][k] - A[j][k];
            // cout << S[i] <<" - " << S[j] << " - " << c << " : " << rest << endl;
            int d = j - i;
            int check = j + d;
            if(rest > 0 && check < n && S[check] == c)
                rest--;
            count += (long long)rest;
        }
    }
    cout << count;
    return 0;
}

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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000000000000001
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool prime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

ll addmod(ll a,ll b)
{
    return (a+b)%mod;
}
ll mulmod(ll a,ll b)
{
    a %=mod;
    b%=mod;
    return (a*b)%mod;
}
ll submod(ll a,ll b)
{
    ll x  = a-b;
    if(x<0)x+=mod;
    x%=mod;
    return x;
}
bool comp(pair<pi,ll>a,pair<pi,ll>b)
{
    if(a.fi.fi==b.fi.fi)return a.fi.se<b.fi.se;
    return a.fi.fi<b.fi.fi;
}


int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
long double a,b; cin>>a>>b;
a = a*b;
ll ans = a;
cout<<ans<<endl;
return 0;
}
/*
5 10 10
22 23
17 19
13 17
8 12
2 6
*/


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


Measured memory_bytes: 2124
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

vals = reads()

ls = sorted((v & 1, v) for v in vals)

if ls[0][0] == ls[2][0]:
  vals = [v for (_, v) in ls]
  M = max(vals)
  ans = sum((M - v) // 2 for v in vals)
  print(ans)
else:
  if ls[0][0] != ls[1][0]:
    (ls[0], ls[2]) = (ls[2], ls[0])
  vals = [v for (_, v) in ls]
  # parity differs in vals[2]
  vals[2] -= 1
  M = max(vals)
  ans = sum((M - v) // 2 for v in vals)
  print(ans + 1)


Measured memory_bytes: 3812
//============================================================================
// Name        : Manji.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
	for(int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			printf("%dx%d=%d\n",i, j, i*j);
		}
	}
	return 0;
}



Measured memory_bytes: 3136
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int A[100000],S[100000];
set<int> s;
int main() {
    int i;
    int N;
    scanf("%d",&N);
    for (i = 0; i < N; i++) scanf("%d",&A[i]),S[i] = A[i];
    sort(S,S+N);

    int ans = 0;
    for (i = 0; i < N; i += 2) s.insert(S[i]);
    for (i = 0; i < N; i += 2) {
        if (!s.count(A[i])) ans++;
    }
    printf("%d\n",ans);

    return 0;
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
struct node{
	int a,b;
}value[N];
int tota,totb,n,sum[N];
int ans;
int Value[N*2];
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld %lld",&value[i].a,&value[i].b);
		Value[i]=value[i].a,Value[i+n]=value[i].b;
		tota+=value[i].a,totb+=value[i].b;
	}
	ans=min(tota,totb);
	sort(Value+1,Value+1+2*n);
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+Value[i];
	for(int i=1;i<=n;i++){
		int fi=value[i].a,se=value[i].b;
		if(fi>se)swap(fi,se);
		if(lower_bound(Value+1,Value+1+2*n,fi)-Value<=n-2){
			if(lower_bound(Value+1,Value+1+2*n,se)-Value<=n-1){
				ans=min(ans,sum[n]);
			}
			else ans=min(ans,sum[n-1]+se);	
		}
		else ans=min(ans,sum[n-2]+fi+se);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4096