akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, k;
  cin >> n >> k;
  vl l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];

  vl dp(n+1);
  dp[1] = 1;
  vl sum(n+1);
  sum[1] = 1;

  rep2(i, 2, n) {
    rep(j, k) {
      dp[i] += sum[max(i-l[j], 0LL)] - sum[max(i-r[j]-1, 0LL)];
      dp[i] %= MOD;
      dp[i] += MOD;
      dp[i] %= MOD;
      sum[i] = sum[i-1] + dp[i];
      sum[i] %= MOD;
    }
  }
  cout << dp[n] << newl;
  return 0;
}

Measured memory_bytes: 6268
#include <stdio.h>
#include <vector>
using namespace std;

int N, K, C[200200], S[200200], E[200200], Z[200200];
vector<int> V[200200], I[200200]; long long A[200200];

void go(int x, int l)
{
	S[x] = ++K;

	auto &i = I[C[x]];
	for (auto &y : V[x]) if (y != l){
		go(y, x);
		int n = Z[y];
		while (!i.empty()){
			int z = i.back();
			if (S[y] <= S[z]){
				n -= Z[z];
				i.pop_back();
			}
			else break;
		}
		A[C[x]] -= 1ll * n * (n + 1) / 2;
	}
	i.push_back(x);

	E[x] = K;
	Z[x] = E[x] - S[x] + 1;
}

int main()
{
	scanf ("%d", &N);
	for (int i = 1; i <= N; i++) scanf ("%d", &C[i]);
	for (int i = 1; i < N; i++){
		int x, y; scanf ("%d %d", &x, &y);
		V[x].push_back(y);
		V[y].push_back(x);
	}
	go(1, 0);

	for (int c = 1; c <= N; c++){
		A[c] += 1ll * N * (N + 1) / 2;
		int n = N;
		for (auto &x : I[c]) n -= Z[x];
		A[c] -= 1ll * n * (n + 1) / 2;
		printf ("%lld\n", A[c]);
	}

	return 0;
}


Measured memory_bytes: 43048
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
p=[]
xy=array(N)
N.times do|i|
    xy[i]=get_i
    p.push(i)
end
perm=p.permutation.to_a
ans=0
perm.each do|arr|
    (N-1).times do|i|
        ans+=((xy[arr[i]][0]-xy[arr[i+1]][0])**2+(xy[arr[i]][1]-xy[arr[i+1]][1])**2)**0.5
    end
end
puts ans/perm.size

Measured memory_bytes: 6780
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int N,M,L,K,A,H;


void solve(){
  vector<PI> G[N];

  bool co[N];
  bool vis[N][M+1];
  CLR(co);
  CLR(vis);
  
  rep(i, L){
    int t;
    cin >> t;
    co[t]=1;
  }

  rep(i, K){
    int x,y,t;
    cin >> x >> y >> t;
    G[x].pb(mp(y,t));
    G[y].pb(mp(x,t));
  }

  priority_queue<pair<int,PI> > q;
  q.push(mp(0,mp(A,M)));
  while(!q.empty()){
    int cc=-q.top().F;
    int cv=q.top().S.F;
    int ct=q.top().S.S;
    q.pop();
    if(vis[cv][ct]) continue;
    //cout << cv << ' ' << ct << ' ' << cc << endl;
    vis[cv][ct]=true;
    if(cv == H){
      cout << cc << endl;
      return;
    }
    if(ct<M && co[cv]) q.push(mp(-cc-1,mp(cv,ct+1)));
    FOR(it,G[cv]){
      if(ct<it->S) continue;
      q.push(mp(-cc-it->S,mp(it->F,ct-it->S)));
    }
  }

  cout << "Help!" << endl;
}



int main(int argc, char *argv[])
{
  while(cin >> N >> M >> L >> K >> A >> H, N)
    solve();
  return 0;
}

Measured memory_bytes: 2240
#include<iostream>
#include<stack>
#include<cstdio>
#include<cstdlib>
using namespace std;

int main()
{
  stack<int> S;
  char c[10];
  int n1,n2;
  while((scanf("%s",&c))!=EOF){
    if(c[0]=='+'){
      n1=S.top();S.pop();
      n2=S.top();S.pop();
      S.push(n1+n2);
    }
    else if(c[0]=='-'){
      n1=S.top();S.pop();
      n2=S.top();S.pop();
      S.push(n2-n1);
    }
    else if(c[0]=='*'){
      n1=S.top();S.pop();
      n2=S.top();S.pop();
      S.push(n1*n2);
    }
    else{
      S.push(atoi(c));
    }
  }
  cout<<S.top()<<endl;
  return 0;
}


Measured memory_bytes: 3252
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        int a,b,c;
        Scanner scanner = new Scanner(System.in);

        a = scanner.nextInt();
        b = scanner.nextInt();
        c = scanner.nextInt();

        int count = 0;
        for(int i = a; i <= b; i++){
            if(c % i == 0){
                count++;
            }
        }

        System.out.println(count);
        scanner.close();
    }
}



Measured memory_bytes: 26272
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define all(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
const int maxn=1009;
int dp[maxn];
int arr[maxn][maxn];
int visited[maxn];
int n;
void check()
{
  //cout<<day<<endl;
  repre(i,0,n)dp[i]=1;
  int match=0;
  int c=0;
  int day=0;
  int flag=0;
  while(++day)
  {
    repre(i,0,n)visited[i]=0;
    match=0;
    repre(i,1,n)
    {
      if(dp[i]==n || visited[i]==1)continue;
      int oppo=arr[i][dp[i]];
      if(visited[oppo] || dp[oppo]==n)continue;
      int uskaoppo=arr[oppo][dp[oppo]];
      if(uskaoppo==i)
      {
        visited[i]=1;
        visited[oppo]=1;
        dp[i]++;
        dp[oppo]++;
        if(dp[i]==n)c++;
        if(dp[oppo]==n)c++;
        match=1;
      }
    }
    if(c==n)break;
    if(match==0){flag=1;break;}
  }
  if(c==n)cout<<day<<endl;
  else cout<<"-1"<<endl;
}
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  cin>>n;
  repre(i,1,n)
  {
    repre(j,1,n-1)
    {
      cin>>arr[i][j];
    }
  }
  check();
/*  int low=1;
  int high=(n*(n-1))/2;
  int temp;
  int flag=0;
  while(low<high)
  {
    int mid=(low+high)/2;
    temp=check(mid);
    if(temp==-1)
    {
      flag=1;
      break;
    }
    if(temp==1)high=mid;
    else low=mid+1;
  }
  if(flag==1)cout<<"-1"<<'\n';
  else
  cout<<low<<'\n';*/
  return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define nil -1
using namespace std;

struct node{
	int parent,left,right;
	node():parent(nil){}
};

void preorder(int parent,vector<node>&tree){
	cout<<" "s<<parent;
	int l=tree.at(parent).left,r=tree.at(parent).right;
	if(l!=nil)preorder(l,tree);
	if(r!=nil)preorder(r,tree);
}

void inorder(int parent,vector<node>&tree){
	int l=tree.at(parent).left,r=tree.at(parent).right;
	if(l==nil)cout<<" "s<<parent;
	if(l!=nil)inorder(tree.at(parent).left,tree);
	if(l!=nil)cout<<" "s<<parent;
	if(r!=nil)inorder(tree.at(parent).right,tree);
}

void postorder(int parent,vector<node>&tree){
	int l=tree.at(parent).left,r=tree.at(parent).right;
	if(l!=nil)postorder(l,tree);
	if(l!=nil)cout<<" "s<<l;
	if(r!=nil)postorder(r,tree);
	if(r!=nil)cout<<" "s<<r;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<node>tree(n);
	for(int i=0,id,l,r;i<n;++i){
		cin>>id>>l>>r;
		tree.at(id).left=l,tree.at(id).right=r;
		if(l!=nil)tree.at(l).parent=id;
		if(r!=nil)tree.at(r).parent=id;
	}
	int root=0;
	while(tree.at(root).parent!=nil)++root;
	cout<<"Preorder\n"s;
	preorder(root,tree);
	cout<<"\nInorder\n"s;
	inorder(root,tree);
	cout<<"\nPostorder\n"s;
	postorder(root,tree);
	cout<<" "s<<root<<"\n"s;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
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; }
 
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; }
 
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int h,w,k; cin>>h>>w>>k;
  k--;
  vector<vector<ll>> dp(h+1, vector<ll>(w,0));
  dp[0][0]=1;
  
  rep(i,h){
    rep(j,w){
      for(int bit=0; bit<(1<<(w-1)); bit++){
        bool ok=true;
        for(int k=0; k<w-2; k++){
          // 横棒が連なっている場合
          if((bit&(1<<k)&&(bit&(1<<(k+1))))) ok=false;
        }
        if(!ok) continue;
        int nj=j;
        if(bit&(1<<j)) nj=j+1; // 右へ移動
        else if(j>0 && (bit&(1<<(j-1)))) nj=j-1; // 左に移動
        (dp[i+1][nj]+=dp[i][j])%=MOD;
      }
    }
  }
  cout<<dp[h][k]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
char a[105], b[105];

int main()
{
	scanf("%d%s%s",&n,a,b);
	for(int i=0;i<n;i++) {
		bool flag = true;
		for(int j=i;j<n;j++) {
			if(a[j] != b[j-i]) flag = false;
		}
		if(flag) {printf("%d\n", n+i); return 0;}
	}
	printf("%d\n",2*n);
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
   fast;
   int n;
   cin >> n;
   int a[n];
   f(i,0,n) cin >> a[i];

   int ans = 0 , p = 0;
   f(i,0,n){
      ans += p * a[i];
      p += a[i];
   }

   cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i,j,x=1;
  cin>>n;
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  
  for(i=0;i<n;i++){
    x=a[x-1];
  
    if(x==2){
      cout<<i+1<<endl;
	  return 0;
    }
  }
  
	cout<<-1<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
    #include <string>
    #include <cmath>
    #include <iomanip>
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        long long arr[n][10], arr2[n][11],num, arr3, arr4[n], prof, maxProf= -1000000000;
     
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<10; j++)
            {
                cin >> arr[i][j];
            }
        }
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<11; j++)
            {
                cin >> arr2[i][j];
            }
        }
        for(int i=1; i<1024; i++)
        {
            num = i;
            prof=0;
            for(int k=0; k<n; k++)
            {
                arr4[k]=0;
            }
            for(int j=9; j>=0; j--)
            {
                arr3= num % 2;
                num = num/2;
                for(int k=0; k<n; k++)
                {
                    if(arr[k][j]==arr3 && arr[k][j]==1)
                    {
                        arr4[k]++;
                    }
                }
            }
            for(int k=0; k<n; k++)
            {
                num = arr4[k];
                prof+=arr2[k][num];
            }
            if(maxProf<prof)
            {
                maxProf = prof;
            }
        }
        cout << maxProf;
        return 0;
    }

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,a,b,c,x,y;
	scanf("%d %d %d",&a,&b,&c);
	y=0;
	for(i=a;i<=b;i++){
		x=c%i;
		if(x==0){
			y=y+1;
		}
	}
	printf("%d\n",y);
	return 0;
}


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

int main() {
  long long N,M;
  cin>>N>>M;
  vector<long long>H(N);
  for(long long i=0;i<N;i++){
    cin>>H.at(i);
  }
  vector<long long>A(M),B(M);
  for(long long i=0;i<M;i++){
    cin>>A.at(i)>>B.at(i);
  }
  vector<long long>ans(N,0);
  for(long long i=0;i<M;i++){
    
    if(H.at(A.at(i)-1)>H.at(B.at(i)-1)){
      ans.at(B.at(i)-1)=1;
    }
    if(H.at(A.at(i)-1)<H.at(B.at(i)-1)){
      ans.at(A.at(i)-1)=1;
    }
    if(H.at(A.at(i)-1)==H.at(B.at(i)-1)){
      ans.at(A.at(i)-1)=1;
      ans.at(B.at(i)-1)=1;
    }
  }
  long long X=0;
  for(long long i=0;i<N;i++){
    if(ans.at(i)==1){
      X++;
    }
  }
  cout<<N-X<< endl;
}
  
    
  
  
  
  
      


Measured memory_bytes: 6428
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
int main()
{
    int t;
    cin >> t;
    if (t>=30) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3624
from collections import Counter

n = int(input())
s = list(input())
c = Counter(s)
total = c['R'] * c['G'] * c['B']
count = 0
for i in range(n):
	for j in range(i + 1, n):
			k = 2 * j - i
			if k < n and s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
				count += 1
print(total - count)


Measured memory_bytes: 9484
use std::str::FromStr;
use std::io::stdin;
use std::cmp::min;

fn main() {
    let (n, m) = {
        let vec: Vec<usize> = read_vec();
        (vec[0], vec[1])
    };
    let mut keys: Vec<(u64, usize)> = Vec::with_capacity(m);
    for _ in 0..m {
        let (a, b) = {
            let line: Vec<u64> = read_vec();
            (line[0], line[1] as usize)
        };
        let open: Vec<usize> = read_vec();
        let mut bit: usize = 0;
        for j in 0..b {
            bit += 1 << (open[j] - 1)
        }
        keys.push((a, bit))
    }
    let mut dp: Vec<u64> = Vec::with_capacity(1 << n);
    for _ in 0..(1 << n) { dp.push(1000000001) }
    dp[0] = 0;
    for i in 0..m {
        let (value, bit) = keys[i];
        for j in 0..(1 << n) {
            let k = j | bit;
            dp[k] = min(dp[j] + value, dp[k]);
        }
    }
    let ans = match dp.last() {
        Some(&1000000001) => -1 as i64,
        Some(&x) => x as i64,
        _ => -1 as i64,
    };
    println!("{}", ans);
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

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

int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N;
  cin>>N;
  int A[N+2];
  memset(A,0,sizeof(A));
  for (int i=1; i<=N; i++) {
    cin>>A[i];
  }
  int D=0;
  for (int i=1; i<=N+1; i++) {
    D+=abs(A[i]-A[i-1]);
  }
  for (int i=1; i<=N; i++) {
    int ans=D-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]);
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 1664
#include <stdio.h>

int w,h;
int b_sum,w_sum;
char map[52][52];

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

void calc_area(int *b_sum,int *w_sum){
	int x,y;

  *b_sum = *w_sum = 0;

  for(y=0;y<h;y++){
    for(x=0;x<w;x++){
      if(map[y][x] == '.' + 1){
        (*b_sum)++;
      }
      else if(map[y][x] == '.' - 1){
        (*w_sum)++;
      }
    }
  }
}

void check_land(int x,int y,char color){
	int i;

	for(i=0;i<4;i++){
		int nx = x + dx[i];
		int ny = y + dy[i];

		if(nx>=0 && ny>=0 && nx<w && ny<h && (map[ny][nx]=='.' || map[ny][nx]=='.'+1)){
			if(color == 'B'){
				if(map[ny][nx] == '.'){
					map[ny][nx]++;
				}
				else{
					continue;
				}
			}
			else{
				if(map[ny][nx] == '.'){
					map[ny][nx]--;
				}
				else if(map[ny][nx] == '.' + 1){
					map[ny][nx]++;
				}
			}

			check_land(nx,ny,color);
		}
	}
}

void get_land(char color){
	int x,y;

	for(y=0;y<h;y++){
		for(x=0;x<w;x++){
			if(map[y][x] == color){
				check_land(x,y,color);
			}
		}
	}
}

int input_map(void){
	int y;

	scanf("%d%d",&w,&h);
	if(w==0 && h==0){
		return 0;
	}

	for(y=0;y<h;y++){
		scanf("%s",map[y]);
	}
	return 1;
}

int main(void){
	int b_sum,w_sum;

	while(1){
		if(input_map() == 0){
			break;
		}

		get_land('B');
		get_land('W');

		calc_area(&b_sum,&w_sum);

		printf("%d %d\n",b_sum,w_sum);
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;

int main() 
{
    ll m[4] = {INF,INF,INF,INF};
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        ll a; cin >> a;
        for(int j = 3; j >= 0; j--){
            sort(m,m+4);
            if(a < m[j]){
                m[j] = a;
                break;
            }
        }
    }
    vector<ll> v;
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 4; j++){
            if(i == j) continue;
            string s = to_string(m[i])+to_string(m[j]);
            int n = stoi(s);
            v.push_back(n);
        }
    }
    sort(v.begin(),v.end());
    cout << v[2] << endl;
}



Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define gr vector<vector<pii>>
#define fi first
#define se second
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    vi res(n);
    for (int i = 0; i < m; i++)
    {
        int pos, x;
        cin >> pos >> x;
        pos--;
        if (res[pos] && res[pos] != x)
        {
            cout << -1 << endl;
            return 0;
        }
        if (!pos && !x && n > 1)
        {
            cout << -1 << endl;
            return 0;
        }
        res[pos] = x;
    }
    if (!res[0] && n > 1)
        res[0] = 1;
    for (int i : res)
        cout << i;
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

# 丸太をk回以下切ってすべてx以下にできる
def c(a, k, x):
    cnt = 0
    for log in a:
        if log < x:
            continue
        if log % x == 0:
            cnt += log // x - 1
        else:
            cnt += log // x
        if cnt > k:
            return False
    return True


def main():
    input = sys.stdin.buffer.readline
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    lb = 0
    ub = 11 ** 9
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if c(a, k, mid):
            ub = mid
        else:
            lb = mid
    print(ub)


if __name__ == "__main__":
    main()


Measured memory_bytes: 29156
#include"bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
	int N;
	cin >> N;
	for (int i = 1;i <= 9;++i) {
		for (int j = 1;j <= 9;++j) {
			if (i * j == N) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t=1;
    // cin >> t;
    while (t--) {
        int n;;
        cin>>n;
        string s;
        cin>>s;
        char s1=s[0];
        int i=0;
        vector<char> v;
        for(i=1;i<n;i++){
            char q=s[i];
            if(s1==q){
                continue;
            }
            else{
                //cout<<s1;
                v.push_back(s1);
                s1=s[i];
            }
        }
        if(s1==s[n]){
            continue;
        }
        else{
            //cout<<s[n-1];
            v.push_back(s[n-1]);
            cout<<v.size()<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  vector<ll> a(3);
  ll odd=0,ans=0;

  rep(i,3){
  	cin>>a[i];
  	if(a[i]%2){
  		odd++;
  	}
  }
  if(odd==2){
  	rep(i,3){
	  	if(a[i]%2){
	  		a[i]++;
	  	}
	  }
  	ans++;
  }else if(odd==1){
  	rep(i,3){
	  	if(a[i]%2==0){
	  		a[i]++;
	  	}
	  }
  	ans++;
  }

  ll maxn=max(a[0],max(a[1],a[2]));
  rep(i,3){
  	ans+=(maxn-a[i])/2;
  }
  cout<<ans<<endl;
  return 0;
}

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

struct Dice {
    int s[6];
    void roll (char c) {
        int b;
        if (c == 'E') {
            b = s[0];
            s[0] = s[3];
            s[3] = s[5];
            s[5] = s[2];
            s[2] = b;
        }
        if (c == 'W') {
            b = s[0];
            s[0] = s[2];
            s[2] = s[5];
            s[5] = s[3];
            s[3] = b;
        }
        if (c == 'N') {
            b = s[0];
            s[0] = s[1];
            s[1] = s[5];
            s[5] = s[4];
            s[4] = b;
        }
        if (c == 'S') {
            b = s[0];
            s[0] = s[4];
            s[4] = s[5];
            s[5] = s[1];
            s[1] = b;
        }
        if (c == 'R') {
            b = s[1];
            s[1] = s[2];
            s[2] = s[4];
            s[4] = s[3];
            s[3] = b;
        }
    }
    int top () {
        return s[0];
    }
    int front () {
        return s[1];
    }
    int left () {
        return s[3];
    }
    int right () {
        return s[2];
    }
};

bool f(Dice a, Dice b) {
    for (int i = 0; i < 6; i++) {
        if (a.s[i] != b.s[i]) {
            return false;
        }
    }
    return true;
}

int main() {

  int n;
  cin >> n;

  vector<Dice> d(n);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
        cin >> d[i].s[j];
    }
  }

  string answer = "Yes";

  for (int k = 0; k < n-1; k++) {
    for (int l = k + 1; l < n; l++) {

        bool check = false;

        for (int i = 0; i < 4; i++) {
            d[l].roll('R');
            for (int j = 0; j < 4; j++) {
                d[l].roll('N');
                if (f(d[k], d[l])) {
                    check = true;
                }
            }
        }

        d[l].roll('E');
        for (int i = 0; i < 4; i++) {
            d[l].roll('N');
            if (f(d[k], d[l])) {
                check = true;
            }
        }

        d[l].roll('W');
        d[l].roll('W');
        for (int i = 0; i < 4; i++) {
            d[l].roll('N');
            if (f(d[k], d[l])) {
                check = true;
            }
        }

        if (check) {
            answer = "No";
        }

    }
  }

  cout << answer << endl;

  return 0;

}


Measured memory_bytes: 3232
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	s, _, a, b, u := readString(), readString(), readInt(), readInt(), readString()

	if u == s {
		a--
	} else {
		b--
	}

	fmt.Println(a, b)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String args []) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int h[] = new int[n+1];
        int ma[] = new int[n+1];

        for (int i = 1; i<=n; i++ ) {
            h[i] = sc.nextInt();
            ma[i] = 0;
        }

        for (int j= 1; j <= m; j++ ) {
            int a, b;
            a = sc.nextInt();
            b = sc.nextInt();
            ma[a] = Math.max(ma[a], h[b]);
            ma[b] = Math.max(ma[b], h[a]);
        }

        int count = 0;

        for (int k= 1; k<=n; k++ ) {
            if (h[k] > ma[k]) {
                count++;
            }
        }
        System.out.println(count);

    }
}


Measured memory_bytes: 59732
str = gets.split
N,K = str[0].to_i, str[1].to_i

str = gets.split
v1 = []
for x in 0...N
  v1[x] = str[x].to_i
end
v2 = v1.reverse

max = 0
a = 0

v = []
w = []
r = N<K ? N : K
s = 0
for x in 1..r
  s = x + (K-x)/2
  if s >= N
    v = v1
    v.sort!.reverse!
    w = v[0...x]
    a = w.inject(:+)
    if a > max
      max = a
    end
  else
    v = v1[0...s]
    v.sort!.reverse!
    w = v[0...x]
    a = w.inject(:+)
    if a > max
      max = a
    end
    v = v2[0...s]
    v.sort!.reverse!
    w = v[0...x]
    a = w.inject(:+)
    if a > max
      max = a
    end
    if s>=2
      for y in 0..s-2
        v = v1[0..y]+v2[0..(s-2-y)]
        v.sort!.reverse!
        w = v[0...x]
        a = w.inject(:+)
        if a > max
          max = a
        end
      end
    end
  end
end

puts max

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
typedef long long L;
L n,m;
int main(){
    while(scanf("%lld%lld",&n,&m)){
        if(n==0&&m==0)return 0;
        L ar[n+1],arr[m+1],sum1=0,sum2=0,mn=999999999999,x,y;
        for(L i=0;i<n;i++){
            scanf("%lld",&ar[i]);
            sum1+=ar[i];
        }
        for(L i=0;i<m;i++){
            scanf("%lld",&arr[i]);
            sum2+=arr[i];
        }
        sort(ar,ar+n);
        sort(arr,arr+m);
        for(L i=0;i<n;i++){
            for(L j=0;j<m;j++){
                if((sum1-ar[i]+arr[j])==(sum2-arr[j]+ar[i])){
                    if(mn>(ar[i]+arr[j])){
                        mn=ar[i]+arr[j];
                        x=ar[i];y=arr[j];
                    }
                }
            }
        }
        if(mn!=999999999999)printf("%lld %lld\n",x,y);
        else printf("-1\n");
    }
    return 0;
}



Measured memory_bytes: 3192
N = int(raw_input())

dist = [0]*(N+1)
mod = 10**9 + 7
dist[1] = 1

for i in range(1,N+1):
    for j in range(2,i+1):
        while i%j == 0:
            dist[j] += 1
            i = i/j
ans = 1
for i in range(2, N+1):
    if dist[i] != 0:
        ans = ans*(dist[i]+1)%mod

print ans



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

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    int a[n+1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    long long psr[n+2], ps2[n+1];
    ps2[0] = 0, ps2[1] = a[1];
    for (int i = 2; i <= n; i++) {
        ps2[i] = ps2[i-2] + a[i];
    }
    psr[n+1] = 0;
    for (int i = n; i > 0; i--) {
        psr[i] = psr[i+1] + a[i];
    }

    for (int i = 0; i < q; i++) {
        int x;
        cin >> x;
        int l = 1, r = n + 1;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            int l2 = 2 * mid - 1 - n;
            if (l2 < 1) {
                l = mid;
                continue;
            }
            
            int r2 = l2 == 1 ? n : lower_bound(a+1, a+n+1, x*2-a[l2-1]) - a - 1;
            if (r2 < mid - 1) {
                r = mid;
            } else {
                l = mid;
            }
        }
        
        cout << psr[l] + (l * 2 - n - 2 > 0 ? ps2[l*2-n-2] : 0) << endl;
    }

    return 0;
}


Measured memory_bytes: 3712
use std::cmp::max;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
    a: usize,
    b: usize,
    c: usize,
    }
    let m = max(max(a, b), max(b, c));
    let l = 3 * m - (a + b + c);
    let ans = if l % 2 == 0 {l / 2}  else {l / 2 + 2};
    println!("{}", ans);
}


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

int main(){
	int n; cin >> n;
	for(int i=n;i<=1111;i++){
		if(i%10==i/10%10 and i/10%10==i/100%10){
			cout<<i<<'\n';
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

struct MaxFlowDinic {
	typedef long long cap_t;

	struct Edge
	{
		int next;
		int inv; /* inverse edge index */
		cap_t res; /* residual */
		cap_t save; /* save whatever you want. TODO: just remove if you don't need */
	};

	int n;
	vector<vector<Edge>> graph;

	vector<int> q, l, start;

	void init(int _n) {
		n = _n;
		graph.resize(n);
		for(int i = 0; i < n; i++) graph[i].clear();
	}
	void addNodes(int count) {
		n += count;
		graph.resize(n);
	}

	void addEdgeSave(int s, int e, cap_t cap, cap_t save) {
		Edge forward = { e, (int)graph[e].size() + (s == e ? 1 : 0), cap, save};
		Edge reverse = { s, (int)graph[s].size(), 0, -1};
		graph[s].push_back(forward);
		graph[e].push_back(reverse);
	}

	void addEdge(int s, int e, cap_t cap, cap_t caprev = 0) {
		Edge forward = { e, (int)graph[e].size() + (s == e ? 1 : 0), cap, -1};
		Edge reverse = { s, (int)graph[s].size(), caprev, -1};
		graph[s].push_back(forward);
		graph[e].push_back(reverse);
	}

	bool assignLevel(int source, int sink) {
		int t = 0;
		l.assign(n, 0);
		l[source] = 1;
		q[t++] = source;
		for(int h = 0; h < t && !l[sink]; h++) {
			int cur = q[h];
			for (const auto &edge : graph[cur]) {
				int next = edge.next;
				if (l[next]) continue;
				if (edge.res > 0) {
					l[next] = l[cur] + 1;
					q[t++] = next;
				}
			}
		}
		return l[sink] != 0;
	}

	cap_t blockFlow(int cur, int sink, cap_t currentFlow) {
		if (cur == sink) return currentFlow;
		for (auto &i = start[cur]; i < (int)graph[cur].size(); i++) {
			int next = graph[cur][i].next;
			if (graph[cur][i].res == 0 || l[next] != l[cur]+1)
				continue;
			if (cap_t res = blockFlow(next, sink, min(graph[cur][i].res, currentFlow))) {
				int inv = graph[cur][i].inv;
				graph[cur][i].res -= res;
				graph[next][inv].res += res;
				return res;
			}
		}
		return 0;
	}

	cap_t solve(int source, int sink)
	{
		if (source == sink) {
			// invalid case
			return -1;
		}
		q.resize(n);
		l.resize(n);
		cap_t ans = 0;
		while (assignLevel(source, sink)) {
			start.assign(n, 0);
			while (cap_t flow = blockFlow(source, sink, numeric_limits<cap_t>::max())) {
				ans += flow;
			}
		}
		return ans;
	}
};

int N;

int main()
{
	long long sum = 0;

	scanf ("%d",&N);
	MaxFlowDinic g; g.init(N+2);
	for (int i=1;i<=N;i++){
		int x; scanf ("%d",&x);
		if (x > 0) g.addEdge(i,N+1,x), sum += x;
		if (x < 0) g.addEdge(0,i,-x);
	}

	for (int i=1;i<=N;i++) for (int j=i*2;j<=N;j+=i) g.addEdge(i,j,1e11);

	printf ("%lld\n",sum-g.solve(0,N+1));

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main()
{
    ll n,ans=0;
    vector< ll > v;
    cin>>n;
    for(int x,i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
        if(i==0) continue;
        v[i]=v[i-1]+x;
    }
    sort(v.begin(),v.end());
    for(ll tm,i=0;i<n; )
    {
       ll l=lower_bound(v.begin(),v.end(),v[i])-v.begin();
       ll u=upper_bound(v.begin(),v.end(),v[i])-v.begin();
       tm=u-l;
       if(v[i]==0) {
            ans+=(tm*(tm+1))/2;
       }
       else {
            ans+=(tm*(tm-1))/2;
       }
 
        i=u;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 2420
def main():
    from builtins import int, map, list, print, min
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    K, N = input_number_list()
    A = input_number_list()
    A.sort()
    ans = A[-1] - A[0]
    for i in range(1, N - 1):
        l = A[i] + (K - A[i + 1])
        r = K - A[i] + A[i - 1]
        ans = min(ans, l, r)
    ans = min(ans, K - A[-1] + A[-2])
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
int X;
  
  cin>>X;
  switch(X){
    case 5:
      cout<<"YES";
            break;
  case 3:
      cout<<"YES";
            break;
  case 7:
      cout<<"YES";
            break;
  
    default:
       cout<<"NO";
       break;
  }
}

Measured memory_bytes: 256
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);
    cinai(l,n);
    sort(l.begin(), l.end());

    ll ans=0;
    for(int i=0; i<n-2; i++) {
        for(int j=i+1; j<n-1; j++) {
/*
*/
            auto it=lower_bound(l.begin(), l.end(), l[i]+l[j]);
            int dist=distance(l.begin(), it);
            ans+=dist-j-1;
/*
            if(it!=l.end()) {
                int cnt=distance(it, l.end());
cout<<"i="<<i<<" j="<<j<<" cnt="<<cnt<<endl;
                ans+=cnt;
            }
*/
/*
            for(int k=j+1; k<n && l[i]+l[j]>l[k]; k++) {
                ans++;
            }
*/
        }
    }
    cout<<ans<<endl;

}



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

const int maxn = 3e5+5;
int n,m,l[maxn],r[maxn];
vector<pair<int,int> > g[maxn];
int c[maxn];

int lowbit(int x){return x & (-x);}

int update(int x,int v){
	while(x < maxn){
		c[x] += v;
		x += lowbit(x);
	}
}

int query(int x){
	int res = 0;
	while(x){
		res += c[x];
		x -= lowbit(x);
	}
	return res;
}

void solve(){
	int les = 0;
	for(int i = 1;i <= m;i++){
		int ans = 0;
		for(int j = i;j <= m;j+=i){
			ans += query(j);
		}
		for(int j = 0;j < g[i].size();j++){
			int u = g[i][j].first;
			int v = g[i][j].second;
			update(u,1);
			update(v+1,-1);
		}
		//printf("i = %d ans = %d les = %d\n",i,ans,les);
		printf("%d\n",ans+n-les);
		les += g[i].size();
	}
}

int main(){
	while(scanf("%d %d",&n,&m) != EOF){
		for(int i = 0;i <= n;i++) g[i].clear();
		memset(c,0,sizeof(c));
		for(int i = 1;i <= n;i++){
			scanf("%d %d",&l[i],&r[i]);
			g[r[i]-l[i]+1].push_back(make_pair(l[i],r[i]));
		}
		solve();
	}
	return 0;
}


Measured memory_bytes: 15744
h,w,k=map(int,input().split())
c=[list(input()) for _ in range(h)]
from itertools import combinations as co
g=[[-1]]
for i in range(1,h+1):
  g+=co(range(h),i)
r=[[-1]]
for i in range(1,w+1):
  r+=co(range(w),i)
ans=0
for gl in g:
  for rl in r:
    t=0
    for i in range(h):
      if i not in gl:
        for j in range(w):
          if j not in rl:
            t+=(c[i][j]=='#')
    ans+=(t==k)
print(ans)

Measured memory_bytes: 9160
import math
X = int(input())

def is_prime(x):
    a = int(math.sqrt(X)) + 1#ある数が素数かどうかはO(√A)で判定できる
    for i in range(2,a):
        if x % i == 0:
            return False
    return True#xは素数

for j in range(X,10**5+4):
    if is_prime(j):
        ans = j    
        break
print(ans)

Measured memory_bytes: 9116
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a * b;
        int length = (a * 2) + (b * 2);
        System.out.printf("%d %d\n", area ,length);
        sc.close();
    }
}


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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 1e5 + 5;
const int inf = 1e18 + 2;


void solve(int Case) {
    int x ;
    cin >> x ;
    cout << (1 ^ x) << '\n';
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int Case = 1;
    while(testcase --) {
        solve(Case);
    }
    return 0;
}



Measured memory_bytes: 3644
"use strict"
 
const main = lines => {
 
  const wordArr = [...lines[0]]
  
  let map = {}
  wordArr.forEach(w => {
   	map[w] = map[w] ? map[w] + 1 : 1
  })
  
  const result = Object.keys(map).map(key => map[key]).every(v => v === 2) ? "Yes" : "No"
  
  console.log(result)
 
}
  
main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'))

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1001001001;


int main(void){

	int H, W; cin >> H >> W;
	char S[H][W];
	REP(i,H) REP(j,W) cin >> S[i][j];

	int x[] = {0, 0, -1, 1};
	int y[] = {1, -1, 0, 0};

	int ans = 0;

	REP(i,H){
		REP(j,W){
			if(S[i][j] == '#') continue;
			vector<vector<int>> dist(H, vector<int>(W, INF));
			queue<pair<int, int>> q;
			auto update = [&](int i, int j, int x){
				if(dist[i][j] != INF) return;
				dist[i][j] = x;
				q.push(make_pair(i, j));
			};
			update(i, j, 0);
			while(!q.empty()){
				int a = q.front().first;
				int b = q.front().second; q.pop();
				REP(d, 4){
					int di = a+y[d], dj = b+x[d];
					if(di<0 or di >=H or dj < 0 or dj >= W) continue;
					if(S[di][dj] == '#') continue;
					update(di, dj, dist[a][b]+1);
				}
			}

			REP(a,H){
				REP(b, W){
					if(dist[a][b] == INF) continue;
					ans = max(ans, dist[a][b]);
				}
			}

		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;



signed main() {
    SS(ll,h,w)
    if(h==1||w==1){
        p(1);
        return 0;
    }
    ll ans=h*w/2;
    h*w%2!=0?p(ans+1):p(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
   int R,G;cin>>R>>G;
   cout<<G+G-R<<endl;
}

Measured memory_bytes: 3596
while True:
    try:
        sentence = raw_input().split()
        for index, string in enumerate(sentence):
            if 'peach' in string:
                s = string.find('peach')
                sentence[index] = string[:s] + 'apple' + string[s+5:]
            elif 'apple' in string:
                s = string.find('apple')
                sentence[index] = string[:s] + 'peach' + string[s+5:]
        else:
            print ' '.join(sentence)
    except EOFError:
        break

Measured memory_bytes: 4204